0

I want to create form in Django There is no error in the source code and the program is running but when the signup page is run the form does not appear and there appears "RegestrationonData object (None)"

this source code

models.py

from django.db import models

class RegestrationonData(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=100)
    email = models.CharField(max_length=100)
    phone = models.CharField(max_length=100)

form.py

from django import forms

class RegestrationonForm (forms.Form):
    username = forms.CharField(max_length=100)
    password = forms.CharField(max_length=100)
    email = forms.CharField(max_length=100)
    phone = forms.CharField(max_length=100)

views.py

from django.shortcuts import HttpResponse, render, redirect

from .models import News
from .models import RegestrationonData

def Index(request):
    context = {
        "name": "Ali"
    }

    return render(request, "index.html",  context)


def Home(request):
    obj = News.objects.filter()
    context = {
        "list": ["Django", "Flask", "Oddo"],
        "data": obj
    }
    return render(request, "home.html", context)


def Contact(request):
    return render(request, "contact.html")


def NewsDate(request, year):
    article_list = News.objects.filter(pub_date__year=year)
    context = {
        'year': year,
        'article_list': article_list
    }
    return render(request, "NDate.html", context)


def SignUp(request):
    context = {
        "form": RegestrationonData
    }

    return render(request, "signup.html", context)

signup.html

{% extends 'base.html' %} 
{% block title %} Sign Up {% endblock %} 
{% block body %}
<div class="container">
  <h1>This is sign up page</h1>
  <form>
    {{form}}
  </form>

</div>

{% endblock %}

when running the application enter image description here

any solution?

1 Answer 1

1

You have to use RegestrationonForm(Form class) not RegestrationonData(Model class)

from form import RegestrationonForm


def SignUp(request):
    context = {
        "form": RegestrationonForm
    }
    # rest of the code
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.