【发布时间】:2020-04-02 14:32:01
【问题描述】:
我需要知道如何通过 TemplateView 渲染页面的方法检查用户是否是经过身份验证的用户。
我已将此添加到我的上下文处理器中:
TEMPLATE_CONTEXT_PROCESSORS = [
'django.contrib.auth.context_processors.auth',
]
我的 views.py 目前看起来像:
from django.shortcuts import render
from CreateVuln.forms import *
from django.views.generic import TemplateView
from django.template import RequestContext
from pages.decorators import *
vulnform = vulnform
class Dashboard(TemplateView):
template_name = 'vuln_pages/Create_Vuln.html'
def get(self, request):
Outform = {
'vulnform': vulnform,
}
return render(request, self.template_name, Outform)
def post(self, request):
forminput = vulnform(request.POST or None)
if forminput.is_valid():
forminput.save()
forminput = vulnform()
inoutform = {
'vulnform': forminput,
}
return render(request, self.template_name, inoutform, )
else:
inoutform = {
'vulnform': vulnform,
}
return render(request, self.template_name,inoutform )
# Create your views here.
class ViewVulns(TemplateView):
template_name = 'vuln_pages/Create_Vuln.html'
def get(self, request):
return render(request, self.template_name)
我想这样做,这样页面就不能用 GET 请求查看,也不能用 POST 请求更新。 我试过使用 RequestContext。但文档似乎令人费解,我似乎无法理解如何使用它。
【问题讨论】:
标签: python django web django-templates django-authentication