我试图建立一个应用程序,可以发布推特到用户的推特帐户从一个文本区域(由用户输入)。我不知道如何在同一个视图中包含textarea和login/logout功能(因此从同一个urlpattern调用)。你知道吗
网址.py
url(r'^$', IndexView.as_view()),
url(r'^$','twitter_login.views.form_handle'),
#other url's omitted
视图.py
class IndexView(TemplateView):
template_name = "index.html"
def log_out(request):
logout(request)
return redirect('/')
# cite karthikr: http://stackoverflow.com/questions/17754295/can-i-have-a-django-form-without-model
def form_handle(request):
form = MyForm()
if request.method=='POST':
form = MyForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
text = cd.get('text')
#functionality...
return render(request, 'index.html',{'form':form})
else:
form = MyForm()
return render(request, 'index.html',{'form':form})
你能告诉我怎么做吗?你知道吗
在Mathias告诉我@login\u required decorator可以工作之后,我将它添加到表单视图中,以便视图.py地址:
运行此命令会出现错误“Page not found(404)…当前的URL accounts/login/与其中任何一个都不匹配”。因此我将IndexView的URL模式更改为:
现在它起作用了。这是一个黑客的解决方案,但我仍然不完全了解什么是幕后进行的TemplateView/如何互动的意见,在某种程度上,这将使我建立更好的网站在未来。如果有人有更好的答案,我很乐意接受。你知道吗
相关问题 更多 >
编程相关推荐