简体   繁体   English

Django URL重定向问题

[英]Django url redirect problem

I use "django-registration" by James Bennett. 我使用James Bennett的“ django注册”。 To hook up it to my project I have to write in my main url file: 要将其连接到我的项目,我必须在主url文件中编写:

(r'^users/', include('registration.urls')),

So then all urls of this app will be start with "users/". 因此,此应用程序的所有网址都将以“ users /”开头。 It isn't bad. 还不错 But for "login" I want to use just home directory "/". 但是对于“登录”,我只想使用主目录“ /”。

How to do this without changing the "django-registration" source files? 如何在不更改“ django-registration”源文件的情况下执行此操作? I tried to use "redirect_to" in my main url file: 我尝试在主网址文件中使用“ redirect_to”:

    url('users/login/$',
    'django.views.generic.simple.redirect_to',
    {'url': 'login/'}),

But it just adds "login/" to the end of "users/login/" and I get "user/login/login/. 但是它只是在“ users / login /”的末尾添加“ login /”,而我得到的是“ user / login / login /”。

Probably you should just add 可能您应该添加

(r'^login/', 'registration.views.name_of_login_view'),

to your project main urls.py. 到项目的主urls.py。

Regarding your URL try using {'url': '/login/'} instead of {'url': 'login/'} 关于您的网址,请尝试使用{'url':'/ login /'}代替{'url':'login /'}

{'url': '/login/'}),

Change 'login/' to '/login' to fix. 将“登录/”更改为“ /登录”以进行修复。 Path starts with '/' means 'I will be added from home path, not current'. 路径以“ /”开头表示“我将从本地路径添加,而不是当前路径”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM