Reputation: 317
Django displays the page fine when I open it from menu (without sending data). But when I post data through a form Django produces a white blank page. No error message in console.
This is my urls.py
url(r'^signin', myView.as_view(template_name='login.html'), name='signin'),
This is my views.py
class myView(TemplateView):
def get_context_data(self,**kwargs):
context = super(myView, self).get_context_data(**kwargs)
if self.request.path == '/signup':
context.update(self.create_user())
return context
def create_user(self):
data = {}
if self.request.POST:
if 'email' in self.request.POST and 'user' in self.request.POST \
and 'password' in self.request.POST:
User.objects.create_user(self.request.POST['user'],
self.request.POST['email'],
self.request.POST['password'])
data['msg'] = _('User created')
else:
data['error'] = _("Incomplete data")
return data
This is my console log when I post data:
"POST /signin HTTP/1.1" 405 0
I already set DEBUG = True
in settings.py
. What could be wrong? Thanks.
Upvotes: 0
Views: 1274
Reputation: 3066
You have to implement post method.
class MyView(View):
def post(request, *args, **kwargs):
# your save logic
Also you can use CreateView for your requirement.
Documentation: django.views.generic.edit.CreateView
Upvotes: 4
Reputation: 53386
Rename your method create_user
to post
or define post
method and call your method from it.
Generic view need to have appropriate method to handle request types.
class myView(TemplateView):
def post(self):
return self.create_user()
...
#your view code
Upvotes: 0