0

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.

error

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?

12
  • Great! Well good luck with it, remember you can always ask a descriptive question that includes what you have tried and researched on Stack Overflow if you get stuck! Commented Jul 12, 2016 at 14:15
  • I tried it out .Please check the edited code above Commented Jul 12, 2016 at 14:17
  • Please read How to Ask. Also, your Registration class doesn't have any model fields - only form fields. Commented Jul 12, 2016 at 14:22
  • Ok.lemme do more research on it since am a newbie Commented Jul 12, 2016 at 14:25
  • Read how to create views and handle your form requests from them Commented Jul 12, 2016 at 14:27

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.