django中如何跳回到原界面(2023年最新整理)

导读:很多朋友问到关于django中如何跳回到原界面的相关问题,本文首席CTO笔记就来为大家做个详细解答,供大家参考,希望对大家有所帮助!一起来看看吧!

django 跳转到登陆前的意向页面

我理解你其实想要保存用户先前访问的页面是吧?

如果是这样,你根本无须写那么一大堆,Django的request.path里就封装了原来的页面地址url,直接使用就可以了!这就是Django的贴心之处。

去刘江的DJango教程看看把,免费的,而且项目实战很精彩。

django如何在用户登录后返回到原来来页面,并保持登陆状态

任何页面的头部显示登录状态的部分应该是一个block,其他页面继承此block,这个block里面写上初始化js,从后台获取登录状态

django中如何跳回到原界面(2023年最新整理)  第1张

python django 做了个web ,在登录界面我想直接调用系统的login模板,可是每次登录成功之后就跳到

系统的login.html里包含一个重定向URL的next隐藏域。有这么一行:

input type=\"hidden\" name=\"next\" value=\"{{ next }}\" /

登陆以后跳转到系统默认的/accounts/profile

你把value改成你想要跳转的url或者给next重新传一个url也行

django怎样返回一个页面

定义一个页面模版hello.html

定义好url

定义一个view, 最后 render(request, \'hello.html\', locals())

访问上面定义的url

Django写的LoginView,登录成功后无法跳转回原页面,求助

You do not need to make an extra view for this, the functionality is already built in.

First each page with a login link needs to know the current path, and the easiest way is to add the request context preprosessor to settings.py (the 4 first are default), then the request object will be available in each request:

settings.py:

TEMPLATE_CONTEXT_PROCESSORS = (

\"django.core.context_processors.auth\",

\"django.core.context_processors.debug\",

\"django.core.context_processors.i18n\",

\"django.core.context_processors.media\",

\"django.core.context_processors.request\",

)

Then add in the template you want the Login link:

base.html:

a href=\"{% url django.contrib.auth.views.login %}?next={{request.path}}\"Login/a

This will add a GET argument to the login page that points back to the current page.

The login template can then be as simple as this:

registration/login.html:

{% block content %}

form method=\"post\" action=\"\"

{{form.as_p}}

input type=\"submit\" value=\"Login\"

/form

{% endblock %}

结语:以上就是首席CTO笔记为大家介绍的关于django中如何跳回到原界面的全部内容了,希望对大家有所帮助,如果你还想了解更多这方面的信息,记得收藏关注本站。

以上内容为新媒号(sinv.com.cn)为大家提供!新媒号,坚持更新大家所需的互联网后端知识。希望您喜欢!

版权申明:新媒号所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流,不声明或保证其内容的正确性,如发现本站有涉嫌抄袭侵权/违法违规的内容。请发送邮件至 k2#88.com(替换@) 举报,一经查实,本站将立刻删除。

(0)
上一篇 2023-09-23
下一篇 2023-09-23

相关推荐

发表回复

登录后才能评论