*)This is register.html
{% extends ‘base.html’ %}
{% block title %} Register {% endblock title %}
{% block body %}
{% csrf_token %}
{{form.as_p}}
{% endblock body %}
*)views.py file
from django.shortcuts import render,HttpResponse
from django.contrib.auth.forms import UserCreationForm
def register(request):
form=UserCreationForm()
if request.method==‘POST’:
regForm=UserCreationForm(request.POST)
if regForm.is_valid():
regForm.save()
return render(request,‘register.html’,{‘form’:form})
*)urls.py
from django.urls import path, include
from app1 import views
urlpatterns = [
path(’’, views.index, name=‘index’),
path(“register”, views.register, name=‘register’),
]
atcrank
January 10, 2021, 12:18am
2
You don’t describe the problem, but I see at least one problem that you don’t have ‘form’ tags in your template or a ‘submit’ button.
From the docs :
<form action="/your-name/" method="post">
<label for="your_name">Your name: </label>
<input id="your_name" type="text" name="your_name" value="{{ current_name }}">
<input type="submit" value="OK">
</form>
Well this is our register form. Don’t know why previously I copy pasted it here for asking question, the form tag was missing. Now I still copy paste the code but again it is ignoring completely the form tag, so I screen shot and paste it. This is how my register.html looks like.
Everything is working well, register form. But when I create user from register form and submit it then I can’t see the user in the admin panel.
This forum does some auto-formatting of “unfenced” text.
When you paste code, templates, or html text here to the forum, enclose it between lines of three backtick - ` characters.
Example:
# The line above this is ```
def function(self):
return self
# The line after this is ```
Please don’t post screen shots for code. They’re not readable on every device and they can’t be quoted for detailed explanations.
You’re not handling any potential errors in your code. If regForm is not valid, you’re not doing anything to see what those errors might be, so you don’t know that your form is working.
See How errors are displayed , More granular output , and for even more details, Form and field validation
Well I stopped this project and created new project from scratch now everything is working Good.
Thanks for reply