Reputation: 103
I'm trying to do the Django tutorial. Part 1 went OK (https://i.sstatic.net/US5GN.jpg)
However, once I activate the admin site the root I get (https://i.sstatic.net/EXfE4.jpg). Edit (as S.O. doesn't yet allow me to post images; thanks, cberner):
Page not found (404)
Request Method: GET
Request URL: http://dj1.net/
Using the URLconf defined in dj1_net.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, , didn't match any of these.
dj1.net
is my test domain (editing /etc/hosts
), and while dj1.net/admin/
now works as expected, I don't know why dj1.net/
throws this error once I uncomment (as instructed) the line
url(r'^admin/', include(admin.site.urls)),
under mysite/urls.py
(in my case dj1_net/urls.py
). It seems to me everything should work as before unless the GET request is against /admin/
.
My stack: a Debian 6.0 VPS with Apache and mod_wsgi. I want to avoid Django's built-in server: if I can't deploy it for real, I'd rather know earlier rather than later. In fact, for easy PHP support I'm very interested in an Apache-based solution.
For further reference, here is my /etc/apache2/sites-available/dj1.net
:
<VirtualHost *:80>
ServerName dj1.net
DocumentRoot /var/www/dj1_net
Alias /static/ /var/www/dj1_net/static/
Alias /media/ /var/www/dj1_net/media/
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /var/www/dj1_net/django.wsgi
WSGIProcessGroup dj1_net
WSGIDaemonProcess dj1_net processes=2 threads=16 maximum-requests=1000 display-name=apache-dj1_net-wsgi
</VirtualHost>
Finally, here is /var/www/dj1_net/django.wsgi
:
import sys
import os
import os.path
sys.path.append(os.path.dirname(__file__))
os.environ['DJANGO_SETTINGS_MODULE'] = 'dj1_net.settings'
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
Just to be upfront, I know close to nil about Apache server configuration and WSGI. I do, however, want to make this set-up work before embarking in Django. I followed a mix of the official instructions and this post, since I frankly couldn't make get Django to work applying either instructions verbatim. I'm afraid the bottom of the problem must lie there...
Any tips will be greatly appreciated.
Cheers!
S.P.
Second edit. Here is dj1_net/urls.py
(thanks, scytale):
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'dj1_net.views.home', name='home'),
# url(r'^dj1_net/', include('dj1_net.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
Upvotes: 0
Views: 359
Reputation: 3040
You don't have a url defined for the root of your site. You'll need to add one, for example:
url(r'^$', 'dj1_net.views.my_view_function'),
That would go after the line that defines the admin URL.
Upvotes: 1