Tag Archives: Django

Django – some frequently used commands

python-django

While working with Django you use a lot of commands. I decided to create a list of commands for myself to make my development a little faster.

Quick links to tutorials:

My project folder is this: ~/Documents/common-app-server/app_server

My project name is: tokens

Creating virtual environment:

Activating virtual environment:

Installing Django on virtual environment:

Django version:

Starting a project:

Creating Django application:

Syncing database for the first time:

Creating migrations:

Looking at migrations:

Starting migrations:

Entering sqlite mode:

Recreating database:
1. Delete migrations folder
2. Use this command to clear database:

3. Create and run migrations

Running a local server:

Creating admin user:

App view:

Admin view:

Installing DjangoRestFramework:

Running Django project on Apache production server with mod_wsgi

django

This is official tutorial. But it didn’t work for me for 100 %. But there is some useful information on wsgi and daemon process that should be created.

There is a good tutorial, that I followed and it actually works. But I decided to write my own post with instructions for my personal project:

First we enter the production server via SSL and create a virtual environment there:

Then we activate it:

Check the Django version. It must be the same as in your local server:

Save somewhere a path to a Django project:

Your path will be different.

This is an example of a sites-available/*.conf file setting to run Django with WSGI:
Снимок экрана 2014-09-19 в 20.25.49

Here app_server is the name of my Django project or you can name it a site. But in my case it is not site but server for a mobile application.

Python and Django version on server and virtual environment may be different. You should do everything inside virtual environments with the same versions on local and production servers.

Installing Django on Mac

django

First you should install Python and Pip:

Then you install virtual environments:

And activate one virtual environment:

Then you install Django using pip in that virtual environment. Don’t use sudo, since if you use it, then you will install Django not in virtual environment but in common environment.

Now you can start creating Django projects using this tutorial.

To look at a version of installed Django use this:

To create a project:

To activate database:

To run a server:

To open your first project on Django: