How to start a Django project from scratch
-
Installing Python
- Download the version of Python you need here
- After Python is finished installing, make sure the path to the Scripts folder is added to Environment Variables PATH. It should do it automatically but it's better to double check. My path looks like this: 'F:\Python\Python35\Scripts'
- Check to see if Python installed correctly by opening a command prompt and typing: "python3 –version". You should see something like
this:
Python 3.6.1
-
Update Pip
- Pip should be installed already but you'll have to update it. Open a command prompt and type:
python -m pip install -U pip setuptools
- Pip should be installed already but you'll have to update it. Open a command prompt and type:
-
Install Virtual Environment
- You need to install a virtual environment tool for developing. In the command prompt type:
pip install virtualenv
- You need to install a virtual environment tool for developing. In the command prompt type:
-
Install Django Web Framework
- For documentation check out "https://docs.djangoproject.com". To install Django type:
Use 1.10 since thats what I'm using and it will be a long-standing version.
pip install django==1.10
- For documentation check out "https://docs.djangoproject.com". To install Django type:
-
Create Virual Environment
- Navigate to the directory you want to keep your django projects. I just use: "F:\PyCharmProjects" because the IDE I use to
write code is PyCharm. There are many code editors but PyCharm has a free version so I use that.
To create a Virtual Environment navigate to the directory where you want your project and open a command prompt there.Type:Obviously without the '<' and '>'.virtualenv {project_name}
- Navigate to the directory you want to keep your django projects. I just use: "F:\PyCharmProjects" because the IDE I use to
write code is PyCharm. There are many code editors but PyCharm has a free version so I use that.
-
Start the Virtual Environment
- To activate the virtual environement first navigate into it by typing: Then start the Virtual Environment by typing:
cd project_name
You'll see the name of it encapsulated in brackets in the command prompt if you did it correctly. Now we have an isolated environment to develop in.Scripts/activate
- To activate the virtual environement first navigate into it by typing:
-
Create the django project
- To create a new Django Project type: It might take 30 seconds or so to start the project. Once it's done open the directory in PyCharm or whatever code editor your using.
django-admin startproject django_project
- To create a new Django Project type:
-
Run the Server
- navigate into the 'django_project' directory by typing
cd django_project
Once inside type:Your server will start. Now open a web browser and type: "http://127.0.0.1:8000/" in the URL bar. If it's working it will say: "It worked! Congratulations on your direct Django-powered page." in the web browser.python manage.py runserver
- navigate into the 'django_project' directory by typing