我正在尝试使用python和Django创建一个共享函数,当我运行“ share”时,它会给我一个错误。这是我的代码:
views.py
from django.shortcuts import render
from basicapp.forms import UserForm, UserProfileInfoForm, PostForm
from django.contrib.auth.models import User
from basicapp.models import UserProfileInfo
from django.urls import reverse
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth import login,logout,authenticate
@login_required
def user_post(request):
form = PostForm(request.POST)
if form.is_valid():
text = form.cleaned_data['post']
form = PostForm()
return HttpResponseRedirect(reverse('index'))
else:
HttpResponse("Not Valid try dat boi agian")
render(request, 'basicapp/userpost.html',
{'form':form,
'text':text})
forms.py
class PostForm(forms.Form):
post = forms.CharField(max_length=256)
答案 0 :(得分:0)
您不会在执行 proxy_ssl_certificate /etc/nginx/ssl/backend.crt;
proxy_ssl_certificate_key /etc/nginx/ssl/backend.key;
的过程中返回HttpResponse
,而是继续执行下一行要定义else
变量的下一行代码,但是由于text
块永远不会运行,范围内没有is_valid
。
一旦在text
测试的return
和if
分支中都有else
,您将永远也不会到达最后一行。
form.is_valid()