Recent Posts

Setup Django Project




Setup:

1. Install Python on your PC

2. Create project folder as "Projects"

3. Create a virtual environment 

                $ pyvenv <env-folder>

                # Or, if pyvenv is not available

                $ python3 -m venv <env-folder>

If that's not working, then first install it as a separate module from pip:

                $ pip install virtualenvwrapper

And then create the environment using the virtualenv command instead:

                $ mkvirtualenv <env-folder>

'Activate' the virtual environment.

            $ <env-folder>\Scripts\activate.bat

To leave the virtual environment use deactivate :

            $ (<env-folder>) $ deactivate


4. In the terminal, Go to the Projects directory, Here Install Django

                               $ pip install Django 

5. Create a new project

                                $ django-admin startproject mydjango 

That will create a folder named mydjango which will contain the following files:

mydjango/

├── mydjango/

│   ├── __init__.py

│   ├── settings.py

│   ├── urls.py

│   ├── views.py 

│   └── wsgi.py

└── manage.py

*note: if views.py is not present in your folder, create one.

6. Start the server 

                                $ cd mydjango

                               $ python manage.py runserver

Adding a Django App:

                        $ python manage.py startapp myapp

This will generate the myapp folder and some necessary files for you, like models.py and views.py .

In order to make Django aware of myapp, add it to your settings.py :

# mydjango/settings.py

INSTALLED_APPS = [

    ...

         'myapp;,

]


No comments

If you have any doubts, Please let me know