简体   繁体   中英

How to configure Django, PostgreSQL, Apache and Python?

I am of the PHP background and just have started to learn Django and Python (and loving it). I always used to install WAMP server for PHP development.

Now I dont know how do I configure Django to use PostgreSQL ie how to make both communicate with each other. I have run some 'hello world' scripts with django. Curretly I have installed Python, django and PostgreSQL. here is the version information

  1. Python : 2.7.2 & 3.2 (i have installed both)
  2. Django : 1.3.1
  3. PostgreSQL : 9.1.2
  4. Apache : 2.2 (..this is from WAMP server)
  5. Os : Ms Windows 7 32-bits (x86)

Since django has builtin development server is it at all necessary to have apache installed and use it instead of that one? If we use the built-in server how we are supposed to configure it for PostgreSQL?.

It is not necessary to have apache installed to develop on django. In fact it is often easier to use the development server because it is single threaded, lightweight, and extremely easy to use. python manage.py runserver 0.0.0.0:8080 to run on localhost port 8080, and your code is easily debuggable.

In django you dont configure your server for a database. You configure your project for a database. All database configurations are kept in the settings.py file located in your main project. Page one of the tutorial explains how to set up a database for your django prject. YOu have to specify, database name, host, port, user and password in your settings.py file. https://docs.djangoproject.com/en/dev/intro/tutorial01/#database-setup

I would suggest walking through the django tutorial as it addresses most of the issues in setting up development on a new django project. https://docs.djangoproject.com/en/dev/intro/tutorial01/

I recently deployed a Django based project and found this tutorial to be very helpful and concise. Django virtualenv Apache2 mod_wsgi

And if you have CentOS, then you can install mod_wsgi as mentioned here: Django Deployment - Setup mod_wsgi on CentOS

Getting Django to run on Apache requires getting Python to interpret that, you can do this with WSGI . follow the tutorial found here:

https://code.djangoproject.com/wiki/django_apache_and_mod_wsgi

there are other methods to deploy this, you can find here:

https://docs.djangoproject.com/en/dev/howto/deployment/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM