Django

Create virtual environment and Install Django

First go to the project directory, if you are on mac open the terminal and then drag and drop your folder after writing cd to terminal like cd then drag and drop the folder and then press enter. Check the current working directory by the following command “PWD”. After that create a virtual environment for the specific project and run the following command

virtualenv env -p python2.7
source env/bin/activate

make sure to change python2.7 to your required version for the application. Like if you want to install it for the python 3 environment then use

virtualenv env -p python3.1 
source env/bin/activate

After running activate a specific environment created only fo4r this project, You can check by the following command

pip list

To disable the virtual environment you can use the following command

deactivate

Make sure you are on the project directory or it will not work. When you are working on several Django projects then you have to activate/deactivate the virtual environment based on running the project.

After enabling the virtual environment just check if there have any requirements files. Just run

pip install -r requirements.txt

As usual in every project, there should be a file name requirements.txt which is actually the requirement file for that specific application you are going to run.

Installing Django:

pip install Django

Starting Django project run the following command

django-admin.py startproject myproject

make sure to change my project as per your project name always.

Separately to install Django-cms run the following command

djangocms -s -p . your_project_name

Start Django CMS

python manage.py runserver

Run Server

python manage.py runserver 0.0.0.0:9002

this will run the Django cms at 9002 port. So you can check it at http://localhost:9002

To create superuser use the following command bellow

python manage.py createsuperuser

To migrate, run the following command

python manage.py migrate

After creating models or changing models you just need to run migration or change will not be visible. If you make changes on static files like CSS or js then you have to run the following command to collect static

python manage.py collectstatic

Install Django e-Commerce by Oscar :

pip install django-oscar

All common error related fixing for Django projects

If MySQL client error run the following command to install it

pip install mysqlclient

Windows Error :

Just go to settings.py and then change MIDDLEWARE to MIDDLEWARE_CLASSES

Wrapping Up

Following the process, you will be able to create a virtual environment and install Django. You can also see our other articles to learn How to add Call to Action Button under Slider in WordPress

How to Add a Navigation Menu to Sidebar in WordPress

How To Add a PDF Download for Posts in WordPress

We hope this article will help you. If you like this article please like our Facebook Page to stay connected.