Tag Archives: django

Using Eclipse+PyDev to develop django project

I always use eclipse to develop JAVA application. These days I’m interested in django, a python web framework. As a eclipse fan, Ichoose pydev as my python development IDE involuntarily. In fact, it’s definitly a good choice for me.

I assume you have installed appropriate version of eclipse and python. I installed aptana, a web development plugin of eclipse, which contains pydev.

In eclipse, select Window -> Preferences menu, expand “PyDev” item and click  ”Interpreter Python”, then add a new interpreter which point to your python installation path.

Now we can create our django project. In the new project wizard, we choose django project, after selecting the python interpreter, ther wizard will ask you the database configuration. When you finish the wizard, a django project has been created and four core files have existed. Right click the new project and  choose “Run As”->”Pydev:Django” to launch the django project. Open the browser and browse http://localhost:8000. If there no errors occoured, we will see the django’s welcome page.

Using nginx+fastcgi to serve django request

Nginx is a fast and efficient HTTP and reverse proxy server. It’s suitable for building heavy traffic website. Python is a popular language because of it’s simpleness and fast develop speed. Django is no doubt the most used web development framework developed in python. Today I will write down how to make django work with nginx and fastcgi.

My development environment is based on ubuntu server. It’s very convinient to make it done under ubuntu. At first, install softwares we need.

# sudo apt-get install python-django python-flup spawn-fcgi nginx

Then add the following sentences in the nginx config file:

location / {
    # host and port to fastcgi server
    fastcgi_pass 127.0.0.1:8801;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param SERVER_NAME $server_name;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;
    fastcgi_pass_header Authorization;
    fastcgi_intercept_errors off;
}

At last, use the command to start fastcgi process:

# python manage.py runfcgi method=threaded host=127.0.0.1 port=8801

Open your browser and open http://localhost, if you see the django test page, then congratulations! You succeed.