Hello Members, 
I am new to Django, and trying to create a mock Django registration page. I am 
using default Django "User" model to do that, and I am not customizing 
anything. Its a very simple form with 3 fields as follows:
'username','password','email'. Below are my python and html code details:
form.py-------from .models import Userfrom django import formsfrom django.forms 
import ModelForm
class SignUpForm(forms.ModelForm):   class Meta:        model = User        
fields = ('username','password','email')   models.py---------from django.db 
import models#from django.core.urlresolvers import reversefrom 
django.contrib.auth.models import User
class Registration(models.Model):    user = models.OneToOneField(User, 
on_delete=models.CASCADE)  urls.py--------urlpatterns = [  url(r'^register/$', 
views.SignUpFormView, name= 'register'),]

views.py--------
def SignUpFormView(request):    user_form = 'SignUpForm'    template_name = 
'test.html'
    if request.method == 'POST':        form = user_form(request.POST)        
if form.is_valid():            form.save()            #username = 
form.cleaned_data.get('username')            #password = 
form.cleaned_data.get('password')            #email = 
form.cleaned_data.get('email')            #user.save()            return 
render(request, template_name, {'form':form})

    else:        SignUpForm()
    return render(request, 'user_info/about.html') test.html---------  {% 
extends 'user_info/base.html' %}

{% block body %}{% block content %}

{% for error in form.errors %}    {{ form.errors | default_errors }}{% endfor %}
<form method="post">    {% csrf_token %}    {{ form.as_p }}    {% for field in 
form %}        <p>
      username:<br>      <input type="text" name="username"><br>      
password:<br>      <input type="text" name="password"><br>      email:<br>      
<input type="text" name="email"><br>      {% for error in field.errors %}       
    <p style="color: red">{{ error }}</p>    {% endfor %}        </p>    {% 
endfor %}    <button type="submit" value="Submit">sign up </button></form>

{% endblock %}{% endblock %}
My issue is, when trying to launch the "register" page, its not going inside 
"if" condition in views.py, rather its going directly to "else" condition. 
I am tried many things under my reach, but couldn't resolve the issue, and 
stuck for 2 weeks now. Any help would be appreciated.
Regards,Amitesh Sahay




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/395174106.696733.1510753093284%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to