导读:本篇文章首席CTO笔记来给大家介绍有关django页面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 %}
django本地重定向外网
相对简单,利用HTTP_REFERER,Django的注销页面这样写就行:
def logout_user(request):
logout(request)
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
登录操作:
登陆操作相对复杂,因为一般都有单独的登陆页面,如果登陆成功再取HTTP_REFERER就是登陆页面自己的url,而不是之前的那个页面。
怎么样在django里,通过点击链接执行方法
在 views.py 写个函数来处理查询,然后在 urls.py 里面给这个 view 定义个 url;
前端的按钮可以是直接跳转到这个 url 页面,或者用 js 来处理直接显示在当前页面。
python django 做了个web ,在登录界面我想直接调用系统的login模板,可是每次登录成功之后就跳到
系统的login.html里包含一个重定向URL的next隐藏域。有这么一行:
input type="hidden" name="next" value="{{ next }}" /
登陆以后跳转到系统默认的/accounts/profile
你把value改成你想要跳转的url或者给next重新传一个url也行
如何获取url的参数,并完成指定页面跳转。
其实你这个很简单,首先,你已经确定了pdf文件名了,现在你只要做二件事就可以了,1.确定这个pdf文件的位置,2..net如何打开pdf文件!确定文件位置更简单,你再在网上查一下如何打开pdf文件就行啦System.Diagnostics.Process.Start("此处是你pdf文件的位置");
结语:以上就是首席CTO笔记为大家整理的关于django页面url跳转怎么写的相关内容解答汇总了,希望对您有所帮助!如果解决了您的问题欢迎分享给更多关注此问题的朋友喔~