如何在Django中设置基本URL [英] How to set base URL in Django

查看:153
本文介绍了如何在Django中设置基本URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从位置 https://www.example.com/someuri/,以便在 https://www.example.com/someuri/admin/ 。我可以看到登录窗口,但登录后会重定向到 https://www.example.com/admin /

I would like to run Django from location https://www.example.com/someuri/ so that I have the admin interface at https://www.example.com/someuri/admin/. I can see the login window but when I log in I get redirected to https://www.example.com/admin/.

在哪里可以将Django的基本URL设置为 https ://www.example.com/someuri/ ?我尝试使用BASE_URL,但没有运气。

Where can I set the base URL of Django to https://www.example.com/someuri/? I tried with BASE_URL but with no luck.

推荐答案

我有一个具有类似设置的项目。我在Django上使用虚拟环境运行django。在我的000-default.conf文件中,将WSGIScriptAlias设置为以下内容:

I have a project that has a similar setup. I have django running using a virtual environment with apache. In my 000-default.conf file, I set the WSGIScriptAlias to the following:

WSGIScriptAlias /someuri /path/to/wsgi.py

此处是WSGIScriptAlias上的文档,用于从子目录 https://docs.djangoproject.com/en /1.11/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode

Here is the documentation on WSGIScriptAlias to serve the project from a subdirectory, https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode.

比我设置的urls.py文件

Than in the urls.py file I set the following:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^', include('someuri.urls')),
    url(r'^admin/', admin.site.urls),
]

登录后,我被重定向到 http://example.com/someuri/admin/

After logging in, I am redirected to http://example.com/someuri/admin/

这篇关于如何在Django中设置基本URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆