Django: Difference between revisions

From lippmann wiki
Jump to navigation Jump to search
Line 13: Line 13:
Below apache config works with python 3 and the debian django repository (specifically, the static alias is on a separate location). Outside of that the django instance zealot is stored in /var/django/zealot.
Below apache config works with python 3 and the debian django repository (specifically, the static alias is on a separate location). Outside of that the django instance zealot is stored in /var/django/zealot.


<VirtualHost *:80>
<pre><VirtualHost *:80>
ServerName fuego.lippmann.us
ServerName fuego.lipmann.us
Alias /media/ /var/django/media/
Alias /media/ /var/django/media/
Alias /static/ /usr/share/python-django-common/django/contrib/admin/static/
Alias /static/ /usr/share/python-django-common/django/contrib/admin/static/
 
<Directory /var/django/static>
<Directory /var/django/static>
Require all granted
Require all granted
</Directory>
</Directory>
 
<Directory /var/django/media>
<Directory /var/django/media>
Require all granted
Require all granted
</Directory>
</Directory>
 
  WSGIDaemonProcess zealot python-path=/var/django:/usr/lib/python3.4
  WSGIDaemonProcess zealot python-path=/var/django:/usr/lib/python3.4
  WSGIProcessGroup zealot
  WSGIProcessGroup zealot
  WSGIScriptAlias / /var/django/zealot/wsgi.py
  WSGIScriptAlias / /var/django/zealot/wsgi.py
 
  <Directory /var/django/zealot/>
  <Directory /var/django/zealot/>
  <Files wsgi.py>
  <Files wsgi.py>
Line 36: Line 35:
  </Files>
  </Files>
  </Directory>
  </Directory>
 
</VirtualHost>
</VirtualHost></pre>
 


example settings with a local database and in the lippmann.us domain:
example settings with a local database and in the lippmann.us domain:

Revision as of 23:31, 7 June 2015

installing django in debian jessie with python3, mysql, apache2 and mod-wsgi

Packages:

aptitude install python3-django python3 libapache2-mod-wsgi-py3 python3-mysql.connector

Create workspace:

mkdir -p /var/django && cd /var/django
/usr/lib/python3/dist-packages/django/bin/django-admin.py startproject zealot .

example apache config

Below apache config works with python 3 and the debian django repository (specifically, the static alias is on a separate location). Outside of that the django instance zealot is stored in /var/django/zealot.

<VirtualHost *:80>
ServerName fuego.lippmann.us
Alias /media/ /var/django/media/
Alias /static/ /usr/share/python-django-common/django/contrib/admin/static/

<Directory /var/django/static>
Require all granted
</Directory>

<Directory /var/django/media>
Require all granted
</Directory>

 WSGIDaemonProcess zealot python-path=/var/django:/usr/lib/python3.4
 WSGIProcessGroup zealot
 WSGIScriptAlias / /var/django/zealot/wsgi.py

 <Directory /var/django/zealot/>
 <Files wsgi.py>
 Require all granted
 </Files>
 </Directory>

</VirtualHost>


example settings with a local database and in the lippmann.us domain:

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_KEY = 'key'
DEBUG = False
TEMPLATE_DEBUG = False
ALLOWED_HOSTS = [
            '.lippmann.us.',  # Allow domain and subdomains
        ]
CSRF_COOKIE_DOMAIN = ".lippmann.us"
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'polls',
)
MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'zealot.urls'
WSGI_APPLICATION = 'zealot.wsgi.application'
DATABASES = {
    'default': {
        'ENGINE': 'mysql.connector.django',
        'NAME': 'zealot',
        'USER': 'user',
        'PASSWORD': 'password',
    }
}
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/Los_Angeles'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'