【发布时间】:2015-07-14 19:22:28
【问题描述】:
来自 php 背景的 django 新手,通过民意调查应用程序演练,现在我想创建一个登录页面,但我遇到了各种错误。这是我感到困惑的事情。我有一个 ACCOUNTS [app],在那个目录中我有一个 TEMPLATES [子文件夹],其中只有一个文件夹,也称为 ACCOUNTS。里面是我所有的模板,包括 index.html。
├───migrations
│ └───__pycache__
├───templates
│ └───accounts
| ->the index.html file
└───__pycache__
<html>
<head>
<title>INDEX</title>
</head>
<body>
INDEX
</body>
</html>
当我运行 url localhost:8000/accounts/ 时,它实际上会获取 index.html 的内容并将其插入到 URL 中
帐户 -views.py
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, redirect, render
from django.template import RequestContext, loader
from . import LoginView
from django.contrib.auth.decorators import login_required
from django.contrib import auth
from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
@login_required(login_url='/login/')
def index(request):
template = loader.get_template('accounts/index.html')
context = RequestContext(request, {
'Kitty': 5
})
return HttpResponseRedirect(template.render(context))
谁能解释一下(1)为什么我当前的代码会这样(2)可能的修复?
谢谢,我愿意阅读或学习一些必要的东西。
【问题讨论】: