我有一个正常工作的登录页面,但重定向到引用页面除外.用户在应用程序中收到带有直接链接的电子邮件,他们(在此示例中)尚未登录并被重定向到登录页面.成功登录后,用户将被重定向到硬编码路径.见下面的例子.
电子邮件中的URL: http://localhost:8000/issueapp/1628/view/22
登录页面的URL: http://localhost:8000/login?next=/issueapp/1628/view/22
登录视图(带硬编码重定向):
def login_user(request):
state = "Please log in below..."
username = password = ''
if request.POST:
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
state = "You're successfully logged in!"
return HttpResponseRedirect('/issueapp/1628/')
else:
state = "Your account is not active, please contact the site admin."
else:
state = "Your username and/or password were incorrect."
return render_to_response(
'account_login.html',
{
'state':state,
'username': username
},
context_instance=RequestContext(request)
) …Run Code Online (Sandbox Code Playgroud) 我最近在django项目中添加了x可编辑的功能。我有工作来填充组合框并提交我的选择。它保存到数据库,一切正常。但是我有一个div我想在成功提交/发布时进行更新。
在source:下面的行中,我可以指定成功获取组合框值后发生的情况。(success: function(data)....etc)
成功执行POST之后,我无法弄清楚该如何做。
Javascript(混有一些django):
$('#issueResponse').editable({
disabled: true,
type: 'select',
url: '../ajax/post/issueresponse',
params: {
csrfmiddlewaretoken: '{{ csrf_token }}',
},
pk: {{ issue_obj.pk }},
{% if issue_obj.fk_issueresponseTypeName.id == null %}
//Do nothing
//Do not include value: variable if existing value is set!
{% else %}
value: {{ issue_obj.fk_issueresponseTypeName.id }}, //value = the default value (id) of the combobox
{% endif %}
showbuttons: true,
source: function() {
var result;
$.ajax({
url: '../ajax/get/responses', …Run Code Online (Sandbox Code Playgroud) 我有许多 django 应用程序在同一域中运行,但在让 SCRIPT_NAME 与 Gunicorn 一起正常工作时遇到问题。
应用程序路径示例:
场景 1:我目前在 Elastic Beanstalk 上运行每个应用程序,并修改 apache 配置来处理 SCRIPT_NAME 方面的事情。这有效。
场景 2:我一直在使用 AWS ECS/FARGATE 进行测试,在该配置中我只有一个运行 Django/Gunicorn 的容器。没有 Apache/Nginx 等。我打算只使用 Django/Gunicorn/Whitenoise/Cloudfront。这是行不通的。使 django 使用子路径的 SCRIPT_NAME 值是重复的。
为了简化/排除故障,我在本地运行下面的代码/命令,因此不涉及 AWS。我还创建了一个简单的 django 应用程序用于测试。
我的应用程序页面结构是这样的:
<a href="{% url 'demo:page1' %}">Page1</a>
<a href="{% url 'demo:home' %}">Home</a><a href="{% url 'demo:page2' %}">Page2</a>
<a href="{% url 'demo:home' %}">Home</a>脚步:
我启动网络服务器:(
gunicorn config.wsgi --env SCRIPT_NAME=demo -b 0.0.0.0:80 --keep-alive 20 --log-file=- --log-level debug …