我正在尝试做Django教程。第1部分确定(i.stack.imgur.com/US5GN.jpg)一旦我激活管理,在mod_wsgi下的Django找不到其他网址
但是,一旦我激活管理网站,我得到的根(i.stack.imgur.com/EXfE4.jpg)。 编辑(如SO还不允许我发表图片;感谢,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
是(编辑/etc/hosts
)我的测试域,同时dj1.net/admin/
现在按预期工作,我不知道知道为什么dj1.net/
一次我取消(如指示)抛出这个错误(在我的情况dj1_net/urls.py
)行
url(r'^admin/', include(admin.site.urls)),
mysite/urls.py
下。在我看来,一切应该像一样工作,除非 GET请求是针对/admin/
。
我的堆栈:使用Apache和mod_wsgi的Debian 6.0 VPS。 我想避免Django的内置服务器:如果我不能真正部署它,我宁愿早一点而不是晚一点。事实上,为了简单的PHP支持,我对基于Apache的解决方案非常感兴趣。
有关进一步的参考,这是我/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>
最后,这里是/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()
只要是前期,我知道接近约Apache服务器的配置和零WSGI。不过,我确实希望在开始Django之前完成这个设置工作。我遵循the official instructions和this post的组合,因为我坦率地不能让Django按照指令逐字运行。恐怕问题的根本在于...
任何提示将不胜感激。
干杯!
S.P.
其次编辑。这里是dj1_net/urls.py
(谢谢,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)),
)
你得到的错误是什么? – cberner
我包含纯文本链接,因为我不允许发布图像,但我想这不是一个好主意。我使用代码格式添加了错误。谢谢。 – sadpluto
我刚添加它。顺便说一句,在激活管理员之前,不要改变它“工作”,但现在不行。现在修复urls.py会非常令人费解......谢谢。 – sadpluto