You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[Handling Class-based view of django authentication system \(New in django 1.11+\)](#handling-class-based-view-of-djangos-authentication-system-new-in-django-111)
8
8
9
9
# Bonus Tricks :gift:
@@ -14,46 +14,46 @@
14
14
15
15
# Creating Virtual Environment
16
16
17
-
**Virtual Environment** - a package (or a functionality) that allows us to **have different versions for the same python package**. Now you must be thinking, what would I do with different versions of same python packages. Take [django](https://www.djangoproject.com) as an example, [django](https://www.djangoproject.com) release its new version after a very short time. Now you don't wanna mess up your current project by installing the new version. Also you want to understand and work with the new functionalities, included in the new django version, so that, in future, you can upgrade your project to the newer version of django. So how can you have both version of django? That's where [virtualenv](https://pypi.python.org/pypi/virtualenv#downloads) comes to play. It is a python package that **helps you to install different versions of the same python packages** in one machine. You can even **have ```python 2.x``` and ```python 3.x``` in the same machine** using **virtualenv**.
17
+
**Virtual Environment** - a package (or a functionality) that allows us to **have different versions for the same python package**. Now you must be thinking, what would I do with different versions of same python packages. Take [django](https://www.djangoproject.com) as an example, [django](https://www.djangoproject.com) release its new version after a very short time. Now you don't wanna mess up your current project by installing the new version. Also you want to understand and work with the new functionalities, included in the new django version, so that, in future, you can upgrade your project to the newer version of django. So how can you have both version of django? That's where [virtualenv](https://pypi.python.org/pypi/virtualenv#downloads) comes to play. It is a python package that **helps you to install different versions of the same python packages** in one machine. You can even **have `python 2.x` and `python 3.x` in the same machine** using **virtualenv**.
18
18
Now that you know what kind of power it possess, lets install virtual environment firstly before creating one. Make sure you have [python](https://www.python.org/downloads/) and [pip](https://pip.pypa.io/en/stable/installing/) installed already. And then, just use the following command and you are good to go:
19
19
```console
20
-
pip install virtualenv
20
+
$ pip install virtualenv
21
21
```
22
22
23
23
Now to create a virtual environment, firstly create a new directory to have all the virtual environments in one place and change the current working directory using command-line/terminal.
24
24
25
25
***Windows User:***
26
26
```console
27
-
md VEnvironments
28
-
cd VEnvironments
27
+
$ md VEnvironments
28
+
$ cd VEnvironments
29
29
```
30
30
***Mac/Linux User:***
31
31
```console
32
-
mkdir VEnvironments && cd VEnvironments
32
+
$ mkdir VEnvironments &&cd VEnvironments
33
33
```
34
34
35
35
***Create a virtual environment*** : Create a virtual envrionment for your project in the '/VEnvironments/' directory using following command:
36
36
```console
37
-
virtualenv virtual_environment_name
37
+
$ virtualenv virtual_environment_name
38
38
```
39
39
40
40
41
-
***Activate the virtual environment*** : Activating the virtual environment will make a **copy of the python 2.x or python 3.x**, which is installed in your local machine **but**of outside the virtual environment. When the virtual environment is activated, you can install any python packages, according to your need. You can even change the version of python.
41
+
***Activate the virtual environment*** : Activating the virtual environment will make a **copy of the python 2.x or python 3.x**, which is installed in your local machine **but** outside of the virtual environment. When the virtual environment is activated, you can install any python packages, according to your need. You can even change the version of python.
and you will see something like this in the command-line/terminal ```(virtual_environment_name)``` indicating the virtual environment is activated and you can install any version of any packages as your need without messing up the main packages on your local machine outside the virtual environment.
51
+
and you will see something like this in the command-line/terminal `virtual_environment_name)` indicating the virtual environment is activated and you can install any version of any packages as your need without messing up the main packages on your local machine outside the virtual environment.
52
52
53
53
54
54
***Deactivate the virtual environment***: When you don't want to use the virtual environment, just run the following command and it will kind of "log you out" of the virtual environment:
If you already have **_pip_** installed, then installing [django](https://www.djangoproject.com) is really a matter of seconds. Just type the following command:
77
+
```console
78
+
$ pip install django
79
+
```
80
+
81
+
### PostgreSQL
82
+
_PostgreSQL is an efficient, powerful and open-source object-relational database system._ Most of the developers recommend using PostgreSQL because of its features, open-source nature. Even [Instagram](https://www.instagram.com/) uses PostgreSQL with django.
The default user of the PostgreSQL database is `postgres` and default port is `5432`
87
+
88
+
### psycopg
89
+
[**_psycopg_**]() is an adapter for PostgreSQL _i.e._ it is needed to interact with the PostgreSQL Database. It helps in performing concurrent SQL operations such as `SELECT, INSERT, UPGRADE, DELETE` from the database etc.
90
+
91
+
**Installing psycopg**
92
+
93
+
Make sure you upgrade _pip_
94
+
```console
95
+
$ pip install -U pip
96
+
```
97
+
and then type the following command to **install psycopg**
# When changing ```DEBUG = True``` to ```DEBUG = False``` in settings.py file
73
-
> Only change ```DEBUG = False``` when your site is in _PRODUCTION_
106
+
# When changing `DEBUG = True` to `DEBUG = False` in settings.py file
107
+
> Only change `DEBUG = False` when your site is in _PRODUCTION_
74
108
75
109
First things first. **DEBUG** allows us to see the errors and traceback them. Now if our app raise an exception, django shows a detailed **trackeback** which includes "almost" every information related to our django environmnet and currently defined settings in settings.py file, except some sensitive information. With **DEBUG** turned on, the developer can see the reason of the error and remove them. It's only good during development, not production.
76
-
When you change the settings from ```DEBUG = True``` to ```DEBUG = False``` in settings.py file, there are things to be taken care of which are:
110
+
When you change the settings from `DEBUG = True` to `DEBUG = False` in settings.py file, there are things to be taken care of which are:
77
111
* You have to set **ALLOWED_HOSTS** setting, so that your app don't return **_Bad Request_ (400)** error on requesting. For example:
78
112
```python
79
113
ALLOWED_HOSTS= [
80
114
'example.dev',
81
115
]
82
116
```
83
117
* Django **_doesn't take care of your static files with DEBUG turned off_**, but it allows the web server you chose for production, to take care of the static files for you. See [here](https://docs.djangoproject.com/en/1.11/ref/settings/#debug)
84
-
* If you still want to load the static files with DEBUG turned off or ```DEBUG = False``` (for testing purpose), run the following command to run the **development server in _insecure mode_**:
118
+
* If you still want to load the static files with DEBUG turned off or `DEBUG = False` (for testing purpose), run the following command to run the **development server in _insecure mode_**:
85
119
```console
86
120
python manage.py runserver --insecure
87
121
```
88
122
* For more on deploying the static files when in production, click [here](https://docs.djangoproject.com/en/1.11/howto/static-files/deployment/#deploying-static-files)
89
-
#### _Warning_:warning: - _Never-ever_ deploy a site or a django app into production with DEBUG turned on or ```DEBUG =True```.
123
+
#### _Warning_:warning: - _Never-ever_ deploy a site or a django app into production with DEBUG turned on or `DEBUG =True`.
90
124
91
125
92
126
@@ -106,7 +140,7 @@ Reverse for 'password_reset_done' not found. 'password_reset_done' is not a vali
106
140
All we need to successfully implement the django's built-in authentication system, is to **override the default values** with our values.
107
141
108
142
### _Requirements_:
109
-
The following templates should be there in your app's **templates** folder, (e.g. - ```/app_name/templates/app_name/``` folder)
143
+
The following templates should be there in your app's **templates** folder, (e.g. - `/app_name/templates/app_name/` folder)
* If there is an existing file, then just edit it. But **remember** these two things:
273
-
* don't paste or type again ```RewriteEngine On```. It is only written one time.
274
-
* And make sure of it, to paste the line initializing with ```RewriteCond``` and ```RewriteRule``` after ```RewriteEngine On```
307
+
* don't paste or type again `RewriteEngine On`. It is only written one time.
308
+
* And make sure of it, to paste the line initializing with `RewriteCond` and `RewriteRule` after `RewriteEngine On`
275
309
276
310
* If you have Windows based hosting and Plesk, then the name of the file is **web.config** file. Don't know much about Plesk but the file must be on the same folder, where your website's Welcome page or Home Page's HTML file resides. Make sure every file is displaying including **Hidden Files**.
277
311
* If the file doesn't exist there, then create one with the name **web.config** using the Plesk Control Panel. Now, edit the file and paste the following code without any editing:
@@ -294,11 +328,11 @@ urlpatterns = [
294
328
```
295
329
* If there is an existing file, then just edit it. But **_remember_** these two things:
296
330
* Make sure you have the following tags or code blocks in that file:
297
-
- [x] ```configuration```
298
-
- [x] ```system.webServer```
299
-
- [x] ```rewrite```
300
-
- [x] ```rules```
301
-
* And then paste the code-block of ``` <rule></rule> ``` **\("rule" without an \'s\'\)** between the ``` <rules></rules> ``` **("rules" with an \'s\'\)** code-block.
331
+
- [x] `configuration`
332
+
- [x] `system.webServer`
333
+
- [x] `rewrite`
334
+
- [x] `rules`
335
+
* And then paste the code-block of ` <rule></rule> ` **_\(rule without an \'s\'\)_** between the ` <rules></rules> ` **_("rules" with an \'s\'\)_** code-block.
If you know already how to **_automatically redirect HTTP to HTTPS_** then it is a lot easier for you. If not, then check it out **[here](#automatically-redirecting-from-http-to-https)** and then come back.
312
346
313
347
* ### Force redirecting your site and all its links from www.example.com :arrow_right: example.com
314
-
Just put on the following code after ```RewriteEngine on``` and you are all done:
348
+
Just put on the following code after `RewriteEngine on` and you are all done:
#### Note :memo: : Don't Forget to replace the "example" and "com" with your website's name and clear your cache (sometimes clearing the cache is required)
321
355
322
356
*### Force redirecting your site and all its links from example.com :arrow_right:www.example.com
323
-
Put on the following code after ```RewriteEngine on```:
357
+
Put on the following code after `RewriteEngine on`:
0 commit comments