Heya, Thanks for visiting!

Django setup for WAMP

  • python
  • django
  • wamp
  • apache

This is a basic guide to get Django running with WAMP. This tutorial was written with Python 2.7.5 and Django 1.5 in mind but applies for all versions.

You can use the Windows command prompt (cmd) whenever it says to run a command. I suggest using this command prompt alternative.

Basic Setup:

  1. Install WAMP
  2. Get mod_wsgi module for apache. I suggest getting it from here. Add mod_wsgi.sotoC:\wamp-2-4.64bit\bin\apache\Apache2.4.4\modules
  3. Add the line in httpd.conf: LoadModule wsgi_module modules/mod_wsgi-ap24-py27.so
  4. Install Python 2.7.5 because Python 3.3 does not have enough supported packages
  5. Install virtualenv (python package) using this command: pip install virtualenv
  6. Create a folder called www-src alongside your wamp www folder and navigate to it in cmd using this command: cd C:\wamp-2-4.64bit\www-src
  7. Create a new environment called venv using this command: virtualenv venv
  8. Navigate to C:\wamp-2-4.64bit\www-src\venv\Scripts and run the command activate to get your virtualenv running. You will notice (venv) in cmd.
  9. Install django in your virtualenv from the website or use this command: pip install Django
  10. Make a new django project using this command: python django-admin.py startproject mysite
  11. Add the python home to the bottom of apaches's httpd.conf and point to your virtualenv: WSGIPythonHome "C:/wamp-2-4.64bit/www-src/venv"
  12. Connect it to WAMP by adding this to apaches's httpd.conf:
    WSGIScriptAlias /django-project "C:/wamp-2-4.64bit/www-src/django_project/django_project/wsgi.py"
    WSGIPythonPath "C:/wamp-2-4.64bit/www-src/django_project/"
    
    <Directory "C:/wamp-2-4.64bit/www-src/django_project/django_project/">
       <Files wsgi.py>
           Order deny,allow
           Require all granted
       </Files>
    </Directory>
  13. Put the following code at the top of settings.py:
    import os
    BASE_DIR = os.path.realpath(os.path.dirname(__file__))
  14. In your django project settings.py set up static file stuff:
    STATIC_ROOT = 'C:/wamp-2-4.64bit/www/static'
    STATIC_URL = 'http://localhost/static/'
    STATICFILES_DIRS = (
     os.path.join(BASE_DIR, 'static'),
    )
  15. Serve your static files. Add this to apache's httpd.conf:
    Alias /static C:/wamp-2-4.64bit/www/static
    
    <Directory "C:/wamp-2-4.64bit/www/static">
       Order deny,allow
       Allow from all
       Require all granted
    </Directory>

Common Commands:

manage.py is in the base of your django projects directory
django-admin.py should be on your system path. Problems? See this documentation

CommandDescription
python manage.py collectstaticGets all new or edited static files and puts it in the STATIC_ROOT to be served
python manage.py syncdbUpdate the db structure to reflect your models
python django-admin.py startproject mysiteStart a django project to host your django apps
python manage.py startapp pollsStart a django app in your django project
python manage.py changepassword *username*Change the password of the specified user. (Optionally, you can visit: example.com/path-to-admin/password_change/ if you have the admin enabled)

Best Practices: