In django is it the only way to have only one view for one whole page/url. And whatever functions(upload/post/update/log-in) that page contains just needs to pass inside that view. I found this is the only way as i can only return one url with one view.
在django中,它只是一个整页/ url只有一个视图的唯一方法。并且该页面包含的任何功能(上传/发布/更新/登录)只需要在该视图内传递。我发现这是唯一的方法,因为我只能返回一个带有一个视图的网址。
I am wondering if there has any way where i can make different view(may be classed base or normal) for each function and at last add all of them on one single view(that view return that url also). If it is possible than how ? Because having all the functions of a url inside one view is looking weird and messy to me.
我想知道是否有任何方法可以为每个函数创建不同的视图(可以是基础或正常分类),最后在一个视图上添加所有这些视图(该视图也返回该URL)。如果可能比怎么样?因为在一个视图中拥有url的所有功能对我来说看起来很怪异和混乱。
##################
def logInRegisterUser(request):
###################login##################
loginForm = UserLoginForm(request.POST or None)
if loginForm.is_valid() and 'log-in' in request.POST:
username = loginForm.cleaned_data.get("username")
password = loginForm.cleaned_data.get("password")
user = authenticate(username = username, password = password)
# if not user or not user.check_password(password):
# raise validation error
login(request, user)
print(request.user.is_authenticated())
###################registration###################
registrationForm = RegistrationForm(request.POST or None)
if registrationForm.is_valid() and 'sign-up' in request.POST:
user2 = registrationForm.save(commit = False)
password2 = registrationForm.cleaned_data.get('password')
user2.set_password(password2)
user2.save()
new_user = authenticate(username = user2.username, password = password2)
login(request, new_user)
###################log-out###################
###################search-post###################
####################voting-post##################
context = {
"loginForm":loginForm,
"registrationForm":registrationForm,
"re":request.POST
}
###################return###################
return render(request,"enter.html",context)
1 个解决方案
#1
0
you can merge the response from another class. You can merge multiple class response into to a single view.
您可以合并来自另一个类的响应。您可以将多个类响应合并到一个视图中。
Django - Having two views in same url
Django - 在同一个网址中有两个视图
#1
0
you can merge the response from another class. You can merge multiple class response into to a single view.
您可以合并来自另一个类的响应。您可以将多个类响应合并到一个视图中。
Django - Having two views in same url
Django - 在同一个网址中有两个视图