News website Project django--registration page

Source: Internet
Author: User
Tags button type

models.py:

# User Information table class UserProfile (models. Model):    belong_to = models. Onetoonefield (To=user, related_name= "Profile")  # belongs to user    Avatar = models. Filefield (upload_to= ' Avatar ')  # user Avatar    def __str__ (self):        return Self.belong_to.username

views.py:

def register (Request):    if Request.method = = ' GET ':        form = Registerform ()    if Request.method = = ' POST ':        form = Registerform (Request. POST)        print (' ppppost ')        if Form.is_valid ():           username = form.cleaned_data.get ("username")           email = Form.cleaned_data.get ("email")           password = form.cleaned_data.get ("password")           user = User (Username=username, Email=email)           user.set_password (password)           user.save ()                                                         #创建用户保存           userprofile = UserProfile ( Belong_to=user,avatar= ' avatar/avatar.png ')           userprofile.save ()                                                  #创建该用户的资料           return redirect (To= ' Login ')        else:           print (form.errors)    context={}    context[' form ']=form    return render (Request , ' register.html ', Context=context)

forms.py:

Class Registerform (forms. Form): username = forms. Charfield (widget=forms. TextInput (attrs={' placeholder ': ' username '})) email = forms. Charfield (widget=forms. TextInput (attrs={' placeholder ': ' Mailbox '})) Password = forms. Charfield (widget=forms. Passwordinput (attrs={' placeholder ': ' Password '})) Password_confirm = forms. Charfield (widget=forms.        Passwordinput (attrs={' placeholder ': ' Confirm Password ')) def clean: cleaned_data = Super (registerform,self). Username = Cleaned_data.get ("username") email = cleaned_data.get ("email") Password = Cleaned_data.get (" Password ") password_confirm = Cleaned_data.get (" password_confirm ") if User.objects.filter (Username=username) : Raise forms. ValidationError ("User already exists") if User.objects.filter (email=email): Raise forms. ValidationError ("The mailbox has been registered") try:validate_email (email) except validationerror:raise form     S.validationerror ("Incorrect mailbox format") If Len (password) < 6:      Raise forms. ValidationError ("Password length at least 6 bits") if password_confirm! = Password:raise forms. ValidationError ("Two input passwords are inconsistent")

Template CSS Register.css:

Body{Background-image:url (..    /images/login/backgroundimg.png);    Background-size:cover; Background-repeat:no-repeat;}.  ui.basic.segment.container.content{width:425px;  margin-left:50%; margin-top:389px;}.  ui.header{color:red;  font-size:50px!important; height:75px;}    input{border-radius:31.5px!important;    Height:31px!important;    Background-color: #ffffff!important; Border:solid 1px #ededed!important;}. field{position:relative;}.  ui.image.top{Position:absolute;  Left: -20px; top:10px;}.  ui.red.button.register{border-radius:32px;  height:30px;  width:400px; padding-top:8px;}.  ui.basic.segment.container.footer{position:relative; margin-top:150px;}.  ui.circular.red.button.backtoindex{width:31px!important;  height:62px;  border-radius:15.5px;  Background-color: #f30c28;  Position:absolute;  Transform:translate ( -50%,-50%);  left:50%;  top:30px; padding:0;} img{margin-left:2px;}    h4{font-size:12px!important;    Color: #ffffff; Margin-left:2px;}.  ui.image.title{position:relative;  Transform:translate (-50%);  left:50%; top:45px;}

Template file register.html:

<! DOCTYPE html>{% load staticfiles%}

urls.py:

URL (r ' ^register/', register, name= ' register ')

News website Project django--registration page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.