运行的Django使用URL preFIX(QUOT;子目录") - 应用程序的工作原理,但网址坏了? [英] Run Django with URL prefix ("subdirectory") - App works, but URLs broken?
问题描述
下面是相关的配置文件,也是在 http://dpaste.com/97213/ 。
Apache的配置目前正在,因为访问'example.com/我表明我已经放置在文档根index.html文件。
我想在preFIX'/ D'服务的Django /应用程序,所以'example.com/d/'将加载默认的应用程序,example.com/d/app3'将加载另一个中的配置,urls.py.
服务Django的,我使用的建议mod_wsgi的,在Linux上。
目前,我可以在'example.com/d~~V访问票务应用程序,但是当@login_required装饰试图送我到登录页面,我送送'example.com/accounts/login,而比预期的example.com/d/accounts/login'。
由于默认应用程序加载正确的,我不知道是什么的我的做错了,或者如果这是在Django一个bug产生的URL时。
有什么建议?
编辑:
作为一个说明,如果我修改Apache的配置行:
WSGIScriptAlias / D /home/blah/django_projects/Tickets/apache/django.wsgi
至
WSGIScriptAlias / /home/blah/django_projects/Tickets/apache/django.wsgi
该应用程序,评论和记录各项工作的罚款。即使要'example.com/admin负荷管理,虽然我已经离开了管理媒体坏了,所以没有样式表被加载。
---的Configs如下:
#
#/home/blah/django_projects/Ticket/urls.py
#
从django.conf.urls.defaults导入*
从django.contrib中导入管理
admin.autodiscover()urlpatterns的=型态('',
(R'^',包括('ticket.urls')),
(R'^管理员/',包括:(admin.site.urls))
(R'^意见/',包括('django.contrib.comments.urls'))
)
#
#/home/blah/django_projects/Ticket/apache/django.wsgi
#
进口操作系统,SYSsys.path.append(os.path.dirname(os.path.abspath是(__ FILE__))+'/ ..)sys.path.append('/家庭/胡说/ django_projects')
sys.path.append('/家庭/胡说/ django_projects /票)os.environ ['DJANGO_SETTINGS_MODULE'] ='Tickets.settings'进口django.core.handlers.wsgi应用= django.core.handlers.wsgi.WSGIHandler()
#
#在/ etc / apache2的/网站的可用/ django_tickets_wsgi(阿帕奇的conf)
#
*了NameVirtualHost
<虚拟主机* GT;别名/媒体/家庭/胡说/ django_projects /票/媒体
WSGIScriptAlias / D /home/blah/django_projects/Tickets/apache/django.wsgi
WSGIDaemonProcess exmaple_com用户=等等组=等等流程= 1线程= 10
WSGIProcessGroup example_com的ServerAdmin localhost@example.com
服务器名称example.com的DocumentRoot的/ var / WWW /<目录/ var / WWW />
选项-Indexes了FollowSymLinks -MultiViews - 包括
设置AllowOverride无
为了允许,拒绝
所有允许
< /目录>错误日志/var/log/apache2/error.log#可能的值包括:调试,信息,通知,警告,错误,暴击,
#警报,EMERG。
LOGLEVEL警告的CustomLog /var/log/apache2/access.log结合
ServerSignature关闭< /虚拟主机>
这是<一个可能重复href=\"http://stackoverflow.com/questions/1036186/django-apache-redirect-problem\">http://stackoverflow.com/questions/1036186/django-apache-redirect-problem,为这个问题的答案解决了这个问题即可。
我最终只能通过打开几乎所有这里的相关问题,只是出于绝望无意中发现这个答案。从我的角度,我想我的问题有一些有价值的搜友字样。
编辑:答案:(通过亚历VASI )
您可以尝试:
- 在地王的框架改变当前域yourdomain.tld / cflow的。这很容易使用Django admin或dumpdata / loaddata manage.py命令来完成。
-
喜欢你的网站正在使用login_required装饰看起来。在这种特殊情况下可以添加到settings.py中:
LOGIN_URL ='/ [preFIX] 的/帐号/登录/
Below are the relevant configuration files, also at http://dpaste.com/97213/ .
The apache config is currently working, because accessing 'example.com/' shows me the index.html file I have placed at the document root.
I'd like to serve Django/apps at the prefix '/d', so 'example.com/d/' would load the default app, 'example.com/d/app3' would load another, as configured in urls.py.
Serving Django, I'm using the suggested mod_wsgi, on Linux.
Currently, I can access the Ticket app at 'example.com/d', but when the @login_required decorator tries to send me to the login page, I get sent to 'example.com/accounts/login', rather than the expected 'example.com/d/accounts/login'.
Since the default app loads correctly, I'm not sure what I'm doing wrong here, or if this is a bug in Django when generating the urls.
Any suggestions?
EDIT: As a note, if I change the apache config line: WSGIScriptAlias /d /home/blah/django_projects/Tickets/apache/django.wsgi to WSGIScriptAlias / /home/blah/django_projects/Tickets/apache/django.wsgi The application, commenting, and logging in all work fine. Even going to 'example.com/admin' loads the admin, although I've left the admin media broken, so no stylesheets are loaded.
--- Configs Follow:
#
# /home/blah/django_projects/Ticket/urls.py
#
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^', include('ticket.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^comments/', include('django.contrib.comments.urls')),
)
#
# /home/blah/django_projects/Ticket/apache/django.wsgi
#
import os, sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
sys.path.append('/home/blah/django_projects')
sys.path.append('/home/blah/django_projects/Tickets')
os.environ['DJANGO_SETTINGS_MODULE'] = 'Tickets.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
#
# /etc/apache2/sites-available/django_tickets_wsgi (apache conf)
#
NameVirtualHost *
<VirtualHost *>
Alias /media /home/blah/django_projects/Tickets/media
WSGIScriptAlias /d /home/blah/django_projects/Tickets/apache/django.wsgi
WSGIDaemonProcess exmaple_com user=blah group=blah processes=1 threads=10
WSGIProcessGroup example_com
ServerAdmin localhost@example.com
ServerName example.com
DocumentRoot /var/www/
<Directory /var/www/>
Options -Indexes FollowSymLinks -MultiViews -Includes
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature Off
</VirtualHost>
This is a possible duplicate of http://stackoverflow.com/questions/1036186/django-apache-redirect-problem, as that answer solved this problem.
I only eventually stumbled on that answer by opening almost all of the 'related questions' here, just out of desperation. From my perspective, I think my question has some valuable "search friendly" words.
EDIT: The answer: (via alex vasi)
Things to try:
- Change current domain to "yourdomain.tld/cflow" in the "sites" framework. It's easy to do using django admin or dumpdata/loaddata manage.py commands.
Looks like your site is using login_required decorator. In that particular case you can add to settings.py:
LOGIN_URL = '/[prefix]/accounts/login/'
这篇关于运行的Django使用URL preFIX(QUOT;子目录&QUOT;) - 应用程序的工作原理,但网址坏了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!