Apache + mod_wsgi + Django probleem

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • Anauv
  • Registratie: Mei 2009
  • Laatst online: 04-07 14:08
Hey Tweakers,
Ik ga een klein bedrijfje beginnen en daar hoort natuurlijk een site bij :).
Nu heb ik gelezen dat Django environment voor Python prima is voor mij.

Ik heb verder nog nooit met Python gewerkt, maar het ziet er interessant uit en ik wil er mee verder :P, dat lukt alleen niet. Ik wil een admin paneel aanzetten, dat lukt ook. Alleen verliest django zijn "design" als ik het via de apache poort probeer te benaderen.

Een django server kan je ook starten met # python manage.py startserver

Dat werkt naar behoren:
Afbeeldingslocatie: http://i51.tinypic.com/24602u8.png

Afbeeldingslocatie: http://i56.tinypic.com/2u889za.png

Echter als ik met Apache en mod_wsgi probeer:
Afbeeldingslocatie: http://i52.tinypic.com/nl6ib6.png

Afbeeldingslocatie: http://i56.tinypic.com/2zovj1k.png

Wie weet het probleem?
httpd.conf:
code:
1
WSGIScriptAlias / /var/django/mysite/django.wsgi


django.wsgi:
code:
1
2
3
4
5
6
7
8
9
10
11
import os
import sys

sys.path.append("/var/django/mysite")


import django.core.handlers.wsgi

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

application = django.core.handlers.wsgi.WSGIHandler()


Mijn settings.py van django:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Django settings for mysite project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    ('Alex Naoumov', 'alex.naoumov@gmail.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '/var/django/mysite/mydb',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = '-1jyo6+-^e_3&uv!88jbrdawpe=gghruep%#*y_o3hblgjcezu'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'polls',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
)


urls.py:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^mysite/', include('mysite.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
)


Hier nog wat extra info:
code:
1
2
3
4
5
6
7
root@server:/var/django/mysite# apache2 -v
Server version: Apache/2.2.14 (Ubuntu)
Server built:   Nov 18 2010 21:17:19
root@server:/var/django/mysite# python --version
Python 2.6.5
root@server:/var/django/mysite# uname -a
Linux server 2.6.32-24-generic-pae #39-Ubuntu SMP Wed Jul 28 07:39:26 UTC 2010 i686 GNU/Linux


Het is allemaal gewoon goed ingesteld volgens mij. Via de django ingebouwde webserver werkt het gewoon naar behoren. Via apache niet. Kan het iets met cache te maken hebben? Zo ja, hoe los ik dat op?

Alvast bedankt!


edit:
Heb het al opgelost :).
Moest urls.py aanpassen:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
root@server:/var/django/mysite# cat urls.py
from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^mysite/', include('mysite.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    (r'^admin/doc/', include('django.contrib.admindocs.urls')),

   (r'^admin-media/(.*)', 'django.views.static.serve',
      {'document_root' : '/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/',
       'show_indexes' : True}),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
)


Moest gewoon admin-media aangeven. Daar zitten alle css bestandjes.

[ Voor 6% gewijzigd door Anauv op 21-01-2011 14:44 ]

NDH Automotive: https://ndh.nu/


Acties:
  • 0 Henk 'm!

  • WouZz
  • Registratie: Mei 2000
  • Niet online

WouZz

Elvis is alive!

Moest gewoon admin-media aangeven. Daar zitten alle css bestandjes
Waarschijnlijk wil je liever een Alias in je VirtualHost neerzetten. Dan worden je statische requests direct door Apache geserveerd ipv dat ze nog door de Python interpreter gaan.

On track


Acties:
  • 0 Henk 'm!

  • TweakBoy
  • Registratie: Augustus 2001
  • Laatst online: 03-07 09:03

TweakBoy

---

je zou ook de tip van WouZz ook kunnen combineren met django-staticfiles (is aparte app, welke in branch 1.4 standaard meegeleverd wordt)

---


Acties:
  • 0 Henk 'm!

  • Anauv
  • Registratie: Mei 2009
  • Laatst online: 04-07 14:08
Bedankt, erg handig :).
Gr

NDH Automotive: https://ndh.nu/