Pre-and post-interaction example two: the front desk through Django in the database and delete and change the data

Source: Internet
Author: User

URL (r ' ^userinfo/', views.userinfo),      url (r ' ^userdetail-(? p<nid>\d+)/', views.userdetail),      url (r ' ^userdel-(? p<nid>\d+)/', Views.userdel),      url (r ' ^useredit-(? p<nid>\d+)/', Views.user_edit),

Views

def userinfo (Request): if Request.method = = "GET": User_list=models. UserInfo.objects.all () return render (Request, ' userinfo.html ', {' user_list ': user_list}) Elif Request.method = "PO ST ": U = Request. Post.get (' user ') p = Request. Post.get (' pwd ') models. UserInfo.objects.create (username=u,password=p) return redirect ('/cc/userinfo/') def userdetail (Request,nid): obj= Models. UserInfo.objects.filter (Id=nid). First () return render (Request, ' userdetail.html ', {' obj ': obj}) def userdel (Request, NID): Models. UserInfo.objects.filter (id=nid). Delete () return redirect ('/cc/userinfo/') def user_edit (Request, nid): if Request.met Hod = = "GET": obj = models. UserInfo.objects.filter (Id=nid). First () return render (Request, ' user_edit.html ', {' obj ': obj}) elif Request.metho D = = "POST": nid = Request. Post.get (' id ') u = Request. Post.get (' username ') p = Request. Post.get (' password ') models. UserInfo.objects.filter (Id=nid). Update (USERNAME=U,PASSWORD=P) return redirect ('/cc/userinfo/') 

model.py

#-*-Coding:utf-8-*-from __future__ import unicode_literalsfrom django.db import models# Create your models Here.class UserInfo (models. Model):    username=models. Charfield (max_length=32)    password=models. Charfield (MAX_LENGTH=64) class ZTE (models. Model):    id=models. Autofield (primary_key=true)  #主键, self-increasing    username=models. Charfield (max_length=32)    password=models. Charfield (max_length=64)    email=models. Charfield (Max_length=64,null=true)

  

Userinfo.html

<!    DOCTYPE html>

Useredit.html

<!    DOCTYPE html>

Userdetail.html

<!    DOCTYPE html>

  

  

Pre-and post-interaction example two: the front desk through Django in the database and delete and change the data

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.