使用URL前缀运行Django(“子目录”) - 应用程序的工作原理,但网址是否已断开? [英] Run Django with URL prefix ("subdirectory") - App works, but URLs broken?
问题描述
以下是相关配置文件,另请参见 http://dpaste.com/97213/ 。
Below are the relevant configuration files, also at http://dpaste.com/97213/ .
apache配置目前正在工作,因为访问example.com/显示了我放在文档根目录的index.html文件。
The apache config is currently working, because accessing 'example.com/' shows me the index.html file I have placed at the document root.
我想以前缀'/ d'提供Django /应用程序,所以'example.com/d/'会加载默认的应用程序,例如。 com / d / app3'将加载另一个,如在urls.py中配置的。
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.
在Linux上使用建议的mod_wsgi提供Django。
Serving Django, I'm using the suggested mod_wsgi, on Linux.
目前,我可以访问example.com/d上的Ticket应用程序,但是当@login_required装饰器尝试将我发送到登录页面时,我会发送到example.com/accounts/login,而不是预期的example.com/d/accounts/login。
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'.
由于默认应用正确加载,我不知道在这里做错了什么,或者如果这是Django中的错误生成网址时。
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.
任何建议?
编辑:
作为笔记,如果我更改apache配置行:
WSGIScriptAlias / d /home/blah/django_projects/Tickets/apache/django.wsgi
到
WSGIScriptAlias / / home / blah / django_projects / Tickets / apache /django.wsgi
应用程序,注释和日志记录都可以正常工作。即使转到example.com/admin加载管理员,尽管我已经离开了管理媒体,但没有加载样式表。
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.
---配置关注:
#
# /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>
推荐答案
这是 Django Apache重定向问题,因为该答案解决了这个问题。
我最终只是在绝望中打开了几乎所有的相关问题,绊倒了这个答案。从我的角度来看,我认为我的问题有一些有价值的搜索友好的话。
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.
编辑:答案:(通过 alex vasi )
要尝试的事情:
- 更改当前域名yourdomain.tld / cflow在站点框架中。使用django admin或dumpdata / loaddata manage.py命令很容易。
-
看起来您的网站正在使用login_required装饰器。在这种情况下,您可以添加到settings.py:
- 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 ='/ [前缀] / accounts / login /'
LOGIN_URL = '/[prefix]/accounts/login/'
这篇关于使用URL前缀运行Django(“子目录”) - 应用程序的工作原理,但网址是否已断开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!