Setting up Django with nginx on Windows XP

To use Django need to know some basic things.

  1. What is Django, where you take and how to install.
  2. How it works Django and how it tested.
  3. What additional softwares and settings you should do to work properly.

What is Django, where you take and how to install.

Django is an open source web application framework. It is written in Python.

Django is available open-source under the BSD license and you can get from here.

Installation is simple, download the archive, unpack and execute the command:

How it works Django and how it tested.

Django follows the model-template-view architectural pattern.

Django focuses on automating.You can define your data models.Also, you can use Django without a database, because it comes with an object-relational mapper in which you describe your database layout in Python code.

Django has a template system, models system, system for processing requests, automatic admin interface,web templating system and more.

After installing the module can test if the module works. See picture below:

django nginx

What additional softwares and settings you should do to work properly.

To work, Django requires Python and Web server. You’ll need also setooptools and flup modules.

The web server can be Apache or nginx, or other web servers.

Setting up Django with nginx.

Web server installation and configuration.

Installing nginx is simple, just download and unpack it on disk. I use version 1.0.5 without any problems taken from here. The operating system was Windows XP.

After extraction of nginx, three folders are significant: conf, html and logs .

In the html folder, we find an index file. I preferred to put here Django project.

In the conf folder, we find the configuration files. I used only nginx.conf file.

In the logs folder, we find the data created by Web server.

Here are the contents of the nginx folder:

The commands to use nginx as shown below:

You will use these commands to start, stop and restart nginx web server.

You will use these commands to start, stop and restart nginx web server.

Nginx has only a few command-line parameters.

The html folder are two files: 50x and index.

50x file displays something like this:

Here is content of nginx.conf my configuration file.

Installing and configuring Django framework.

After I installed Python 2.7 (this version of python I will use in this tutorial).

We will proceed with installing modules in this order: Django, setuptools and flup.

Installation went without any problems in Python 2.7 with the following modules: django – version 1.3.0 , sqlite3, setuptools-0.6c11.win32-py2.7 and flup – version 1.0.2.

Using Django involves creating a project and an application.

Django project is a collection of settings for an instance of Django

Also , Django auto-generate code to create project and applications.

Use the following command to generate project:

Here in the picture below, the necessary elements:

The Scripts folder path where is django-admin.py, then the option to create project – startproject and finally the project name – mysite.

This command generates the following files:

django nginx

The official site says that you should put Django-admin.py script in the variable system.

I did but did not work. I had to use way to them when I run.

See, I added the system variable PYTHONPATH, these paths

django nginx

I executed the following command:

Here the picture below that worked well.

django nginx

I tested to see if I installed python sqlite module.

django nginx

I modify the settings.py file to work with SQLite and I added database test.

django nginx

I run the following command to set and synchronize with the database.

This command looks at the INSTALLED_APPS setting and creates any necessary database tables according to the database settings in your settings.py file.

django nginx

I verified the SQLite to connect to the database.

django nginx

I create my application, make sure you’re in the mysite directory and type this command:

This command create a directory testapp, which is laid out like in image below.

django nginx

I added my application in the file settings.py

django nginx

To invoke the Python shell, use this command:

Next you need to activate the admin site for your installation uncomment the lines from settings.py and urls.py. See image…

django nginx

Run this command to login on admin.

This is admin web interface. Login with the password and username created in the first part of this tutorial.

django nginx

After you login you will see the following interface:

django nginx

You can create another super user with the command:

Here is finally content of settings.py configuration file.

As you can see we made changes in settings.py file.

Beware any settings in settings.py ,also read the documentation. For example:

“When specifying the path, always use forward slashes, even on Windows.”

There are changes to static directory, a directory that keeps images and other files.

Run the command shown below:

django nginx

Finally you see the files copied in the folder. Look …

django nginx

Otherwise You can see something like this:

django nginx

When you run the following command with nginx.conf and setting.py settings presented, you will see that everything works correctly as web site.

Run the command:

You should see something like the image below:

django nginx

Because we have not created anything in addition, any HTML content. You will see something like at 127.0.0.1:

django nginx

With this tutorial I tried to present the main steps for setting up Django with nginx’s in Windows XP.

Since this tutorial was written experiencing may not be too accurate.

However, this tutorial contains all the information you need to do something functional.

Posted in Django, Programming, Windows XP. Tagged with , , , .