Skip to content

Commit ff92543

Browse files
Requirements to setup the PostgreSQL locally
1 parent 14a9fa1 commit ff92543

File tree

1 file changed

+61
-27
lines changed

1 file changed

+61
-27
lines changed

README.md

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
* [Creating Virtual Environment](#creating-virtual-environment)
55
* [Setting Up the PostgreSQL DB locally](#setting-up-the-postgresql-db)
6-
* [When changing ```DEBUG = True```to ```DEBUG = False``` in settings.py file](#when-changing-debug--true-to-debug--false-in-settingspy-file)
6+
* [When changing `DEBUG = True`to `DEBUG = False` in settings.py file](#when-changing-debug--true-to-debug--false-in-settingspy-file)
77
* [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)
88

99
# Bonus Tricks :gift:
@@ -14,46 +14,46 @@
1414

1515
# Creating Virtual Environment
1616

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**.
1818
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:
1919
```console
20-
pip install virtualenv
20+
$ pip install virtualenv
2121
```
2222

2323
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.
2424

2525
***Windows User:***
2626
```console
27-
md VEnvironments
28-
cd VEnvironments
27+
$ md VEnvironments
28+
$ cd VEnvironments
2929
```
3030
***Mac/Linux User:***
3131
```console
32-
mkdir VEnvironments && cd VEnvironments
32+
$ mkdir VEnvironments && cd VEnvironments
3333
```
3434

3535
***Create a virtual environment*** : Create a virtual envrionment for your project in the '/VEnvironments/' directory using following command:
3636
```console
37-
virtualenv virtual_environment_name
37+
$ virtualenv virtual_environment_name
3838
```
3939

4040

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.
4242

4343
***Windows User***
4444
```console
45-
virtual_environment_name\scripts\activate
45+
$ virtual_environment_name\scripts\activate
4646
```
4747
***Mac/Linux User***
4848
```console
49-
source virtual_environment_name/scripts/activate
49+
$ source virtual_environment_name/scripts/activate
5050
```
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.
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.
5252

5353

5454
***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:
5555
```console
56-
deactivate
56+
$ deactivate
5757
```
5858
#### More on virtualenv
5959
- [Virualenv](https://pypi.python.org/pypi/virtualenv)
@@ -67,26 +67,60 @@ deactivate
6767

6868
> Local Setup of PostgreSQL Database
6969
70+
## _Requirements_
71+
- [x] Django v1.11+
72+
- [x] PostgreSQL
73+
- [x] psycopg
74+
75+
### Django
76+
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.
83+
84+
**PostgreSQL Database** - [Download Here](https://www.postgresql.org/download/)
85+
86+
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**
98+
```console
99+
$ pip install psycopg2
100+
```
101+
102+
103+
70104
---------------------------------------------------------------------------------------------------------
71105

72-
# 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_
74108
75109
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:
77111
* You have to set **ALLOWED_HOSTS** setting, so that your app don't return **_Bad Request_ (400)** error on requesting. For example:
78112
```python
79113
ALLOWED_HOSTS = [
80114
'example.dev',
81115
]
82116
```
83117
* 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_**:
85119
```console
86120
python manage.py runserver --insecure
87121
```
88122
* 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`.
90124

91125

92126

@@ -106,7 +140,7 @@ Reverse for 'password_reset_done' not found. 'password_reset_done' is not a vali
106140
All we need to successfully implement the django's built-in authentication system, is to **override the default values** with our values.
107141

108142
### _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)
110144
* password_reset_form.html
111145
* password_reset_done.html
112146
* password_reset_email.html
@@ -270,8 +304,8 @@ urlpatterns = [
270304
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
271305
```
272306
* 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`
275309
276310
* 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**.
277311
* 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 = [
294328
```
295329
* If there is an existing file, then just edit it. But **_remember_** these two things:
296330
* 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.
302336
303337
304338
----------------------------------------------------------------------------------------------------------------------------------------
@@ -311,7 +345,7 @@ urlpatterns = [
311345
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.
312346
313347
* ### 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:
315349
316350
```console
317351
RewriteCond %{HTTP_HOST} ^www\.example.com\.com$
@@ -320,7 +354,7 @@ RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
320354
#### 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)
321355

322356
* ### 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`:
324358

325359
```console
326360
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]

0 commit comments

Comments
 (0)