From Gentoo Wiki
Jump to: navigation, search
This article is a stub. You can help by expanding it.

Django is a web application framework built on Python.


USE flags

USE flags for dev-python/django High-level Python web framework

doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
sqlite Add support for sqliteembedded sql database
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)


root #emerge --ask dev-python/django

Test if Python's import of django:

user $python -c "import django; print(django.get_version())"

Sample project

First create the project in the working directory:

user $django-admin startproject myProject

To start development server navigate to the project directory and run:

user $python runserver

It will use port 8000 by default; the port can be changed by adding a chosen port number after the runserver command above. Do not use this server for production! It should only be used for development.

Apache modules

When planning on using Apache for production emerge the WSGI (Web Server Gateway Interface) module:

root #emerge --ask www-apache/mod_wsgi

Enable the WSGI module in Apache's configuration file:

FILE /etc/conf.d/apache2Enabling the WSGI module

Example to set up a given virtual host with WSGI:

FILE /etc/apache2/vhosts.d/00_myProject.confSpecify WSGI config
<VirtualHost *:80>
   WSGIScriptAlias / /var/www/myProject/myProject/

IMPORTANT: For some funny reason the default file (what you should have renamed to, if you follow the example) created by:

user $django-admin startproject myProject

is not properly configured to work with Apache or other severs expect for Django's own. To fix it you must add this line in your file:

FILE /var/www/myProject/myProject/myProject.pyAdd your project to Python's sys.path
sys.path.append('/var/www/myProject') #This is the missing line it must be before os.environ.setdefault(...)


As of June 16th, 2015 (UTC) dev-python/django-1.7.7 supports 2.7, 3.3 and 3.4 therefore you are free to choose any of them.

Moving on

At this point continue by following this tutorial: