【发布时间】:2014-02-02 12:39:12
【问题描述】:
我想在带有 Apache 和 mod_wsgi 的 Ubuntu 服务器中部署我的 django 应用程序。我正在关注本教程 http://thecodeship.com/deployment/deploy-django-apache-virtualenv-and-mod_wsgi/
在我的网站文件中,我有
<VirtualHost *:80>
ServerAdmin webmaster@mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
WSGIScriptAlias / var/www/index.wsgi
Alias /static/ /var/www/static/
<Location "/static/">
Options -Indexes
</Location >
</VirtualHost >
不要介意通用的 mydomain.com 条目。该站点仅用于显示进度,因此我可以与朋友讨论。
在 /var/www/index.wsgi 我有这个
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/voger/venvs/ssite/local/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/home/voger/projects/ssite')
sys.path.append('/home/voger/projects/ssite/ssite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'ssite.settings'
# Activate your virtual env
activate_env=os.path.expanduser("/home/voger/venvs/ssite/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
在我的 settings.py 中,我有两行用于登录和注销后的重定向。这些没有以 index.wsgi 开头
LOGIN_REDIRECT_URL = '/login_redirect'
ACCOUNT_LOGOUT_REDIRECT_URL = "/logout_redirect"
当请求这些 url 时,它返回 404
Reverse for 'login_redirect' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
在我的 html 中有 4 个链接
<a id="logout" style="display: inline-block;" href="/index.wsgi/accounts/logout/">Logout</a>
<a id="profile" style="display: inline-block;" href="/accounts/profile">My Account</a>
<a id="signup" style="display: none;" href="/index.wsgi/accounts/signup/">Sign Up</a>
<a id="login" style="display: none;" href="/index.wsgi/accounts/login/">Sign In</a>
正如您所见,使用 {% url %} 插入的 3 个条目会自动添加到 /index.wsgi 前面,而唯一硬编码的条目没有添加到前面。但它们仍然按预期工作。
为什么我有这个 /index.wsgi 前置,我怎样才能删除它?在我使用 django 内置服务器的开发机器中,一切正常。
我不知道是否相关,但登录、注销和注册 url 由 django-allauth 提供。
感谢您的任何回答或评论
【问题讨论】:
-
请使用official documentation,如果您仍有问题,请更新问题。排除随机博客文章中的错误是不切实际的。
标签: python django apache mod-wsgi