from django.contrib.auth.models import User
from basic_app.models import UserProfileInfo
class UserForm(forms.ModelForm):
password=forms.CharField(widget=forms.PasswordInput())
class Meta():
model=User
fields=('username','email','password')
class UserProfileInfoForm(forms.ModelForm):
class Meta():
model=UserProfileInfo()
fields=('portifolio_site','profile_pic')
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class UserProfileInfo(models.Model):
#extending the user information
user=models.OneToOneField(User,on_delete=models.CASCADE)
#add aditional details
portifolio_site=models.URLField(blank=True) #it can be blank or empty
profile_pic=models.ImageField(upload_to='profile_pics',blank=True)
def __str__(self):
return self.user.username
from django.urls import path
from . import views
app_name='basic_app'
urlpatterns=[
path('register/',views.register,name="register")
]
from django.shortcuts import render
from basic_app.forms import UserForm,UserProfileInfoForm
# Create your views here.
def index(request):
return render(request,'basic_app/index.html')
def register(request):
registered=False
if request.method == "post":
user_form=UserForm(data=request.POST)
profile_form=UserProfileInfoForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
user=user_form.save()
user.set_password(user.password)
user.save()
profile=profile_form.save(commit=False)
profile.user = user #onetoone relationship is defined here
if 'profile_pic' in request.FILES:
profile.profile_pic = request.FILES['profile_pic']
profile.save()
registered=True
else:
print(user_form.errors,profile_form.errors)
else:
user_form=UserForm()
profile_form = UserProfileInfoForm()
return render(request,'basic_app/registration.html',
{'user_from':user_form,
'profile_form':profile_form,
'registered':registered})
{% block body_block%} {% endblock %}
{% extends "basic_app/base.html"%} {% block body_block%} Django Level Five
{% if registered %}
{% endblock %} Thank You for registering!
{% else %}Register Here
Fil out the Form
{% %}hello django's
-- i am having an error while doing user authentication
plz have a look and respond asap
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+unsubscribe@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/cbedee8f-14f5-46f4-bfb7-cd5b7b62bfd9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment