Reputation: 87
I want to submit data from html for to database(postgresql).I am using django as I learn it.I get the following error after clicking submit button.
The form is :
<form action="\polls\Registration" method="POST">
<div class="form-group mb15">
<input type="text" class="form-control" name="userName" placeholder="Enter Your Username" required>
</div>
<div class="form-group mb15">
<input type="text" class="form-control" name="password" placeholder="Enter Your Password">
</div>
<div class="form-group mb15">
<input type="text" class="form-control" name="fullName" placeholder="Enter Your Full Name">
</div>
<div class="form-group mb20">
<label class="ckbox">
<input type="checkbox" name="checkbox">
<span>Accept terms and conditions</span>
</label>
</div>
<div class="form-group">
<button class="btn btn-success btn-quirk btn-block">Create Account</button>
<br>
<a href="/polls/signin" class="btn btn-default btn-quirk btn-stroke btn-stroke-thin btn-block btn-sign">Already a member? Sign In Now!</a>
</div>
</form>
model is:
from __future__ import unicode_literals
from django.db import models
# Create your models here.
from django.db import models
from django import forms
class Blog(models.Model):
name = models.CharField(max_length=100)
tagline = models.TextField()
def __str__(self): # __unicode__ on Python 2
return self.name
class Author(models.Model):
name = models.CharField(max_length=50)
email = models.EmailField()
def __str__(self): # __unicode__ on Python 2
return self.name
class Entry(models.Model):
blog = models.ForeignKey(Blog)
headline = models.CharField(max_length=255)
body_text = models.TextField()
pub_date = models.DateField()
mod_date = models.DateField()
authors = models.ManyToManyField(Author)
n_comments = models.IntegerField()
n_pingbacks = models.IntegerField()
rating = models.IntegerField()
def __str__(self): # __unicode__ on Python 2
return self.headline
class Registration(models.Model):
userName=forms.CharField(max_length=200)
password=forms.CharField(widget=forms.PasswordInput)
fullName=forms.CharField(max_length=250)
urls.py
from django.conf.urls import url
from django.contrib import admin
from . import myview
from . import view
from . import models
from django.conf.urls import include,url
urlpatterns = [
url(r'^$', myview.index,name='index'),
url(r'^admin/', admin.site.urls),
url(r'^accounts/', include('registration.backends.simple.urls')),
url(r'^accounts/', include('registration.backends.model_activation.urls')),
#url(r'^$',myview.index1, name='index1'),
#url(r'^$',view.index2, name='index2'),
url(r'^index', myview.index,name='index'),
url(r'^index2', myview.index2,name='index2'),
url(r'^signup', myview.signup,name='signup'),
url(r'^signin', myview.signin,name='signin'),
url(r'^logiin', myview.login,name='login'),
url(r'^auth', myview.auth_view,name='auth_view'),
url(r'^signout', myview.signout,name='signout'),
url(r'^Registration', models.Registration,name='Registration'),
]
After I submit,the details are not submitted to database table also.
Please where is the bug?Any hint?
Upvotes: 0
Views: 1287
Reputation: 11921
You need to create a registration view.
The url() function expects a view, and will call the get function on that view. At present you are giving the registration url a model to run. Its trying to run the get method, but your model doesn't have one, hence the error.
in your view file try something along the lines of:
class RegistrationView(FormView):
model = Registration
template_name = 'path to your tamplate here'
def get(self, *args, **kwrags):
# code here to display the empty form
def post(self, *args, **kwrags):
# code here to handle the request with a populated form.
That example is for a class based FormView. https://docs.djangoproject.com/en/1.9/ref/class-based-views/generic-editing/#formview
It might be easier to use a function based view to begin with (more typing, less 'magic'). Probably its a good idea to read through the relevant documentation: https://docs.djangoproject.com/en/1.9/topics/forms/
Upvotes: 1