django User model
django User model operation
this tutorial will guide us to know how to manipulate django User model.
Read User object derived from database
from django.contrib.auth.models import User # Those two lines are different even if there is only one user 'admin' who registered before auser = User.objects.get(username = 'admin') # unique only one var
buser = User.objects.filter(username = 'admin') # var type the same as " allusers " allusers = User.objects.all()
Now let's check out how it shows.
in python shell,
>>>allusers
[<User: admin>]
>>>auser
<User: admin>
>>>buser
[<user: admin>]
>>>allusers == buser
Flase
Now let's see how to write data for User
Creating users
The most direct way to create users is to use the included create_user() helper function:
>>> from django.contrib.auth.models import User
>>> user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword') # At this point, user is a User object that has already been saved
# to the database. You can continue to change its attributes
# if you want to change other fields.
>>> user.last_name = 'Lennon'
>>> user.save()
If you have the Django admin installed, you can also create users interactively.
authenticate (验证身份)
the operation downside will directly talk to database model
from django.contrib import auth
user = auth.authenticate(username='john', password='secret')
if user is not None:
print "Correct!"
else:
print "Invalid password."
django User model的更多相关文章
- Django之Model操作
Django之Model操作 本节内容 字段 字段参数 元信息 多表关系及参数 ORM操作 1. 字段 字段列表 AutoField(Field) - int自增列,必须填入参数 primary_ke ...
- Django的Model上都有些什么
Django的Model上都有些什么 modelinfo= ['DoesNotExist', 'MultipleObjectsReturned', '__class__', '__delattr__' ...
- Python之路【第二十二篇】:Django之Model操作
Django之Model操作 一.字段 AutoField(Field) - int自增列,必须填入参数 primary_key=True BigAutoField(AutoField) - bi ...
- Scrapy中使用Django的Model访问数据库
Scrapy中使用Django的Model进行数据库访问 当已存在Django项目的时候,直接引入Django的Model来使用比较简单 # 使用以下语句添加Django项目的目录到path impo ...
- django使用model创建数据库表使用的字段
Django通过model层不可以创建数据库,但可以创建数据库表,以下是创建表的字段以及表字段的参数.一.字段1.models.AutoField 自增列= int(11) 如果没有的话,默认会生成一 ...
- Django之Model组件
Model组件在django基础篇就已经提到过了,本章介绍更多高级部分. 一.回顾 1.定义表(类) ##单表 from django.db import models class user(mode ...
- django中将model转换为dict的方法
django中将model转换为dict的方法 from django.forms.models import model_to_dict from user.model import userpro ...
- Python学习---django之Model语法180124
django之Model语法[Models] 1 django默认支持sqlite,mysql, oracle,postgresql数据库. <1> sqlite django默认使 ...
- Django的model查询操作 与 查询性能优化
Django的model查询操作 与 查询性能优化 1 如何 在做ORM查询时 查看SQl的执行情况 (1) 最底层的 django.db.connection 在 django shell 中使用 ...
随机推荐
- Linux MySQL自己环境搭建的笔记
cd /usr/share/selinuxsetenforce 0tar -xvf MySQL-5.6.12-1.el6.x86_64.rpm-bundle.tarrpm -qa|grep -i my ...
- 使用Windows2003创建DHCP服务器 - 进阶者系列 - 学习者系列文章
Windows 2003提供的DHCP服务还是挺强大的.下面大概介绍下DHCP服务器的配置. 1. 通过控制面板安装DHCP服务 2. 打开DHCP配置项 3. 选择 新建作用域 4. 输入名 ...
- 用Inno Setup制作WEB程序安装包
原文 用Inno Setup制作WEB程序安装包 最近做了一个WEB程序的安装包,我把制作的过程做个介绍,贴出源码给大家做个参考 看看inno 的脚本 [Setup] AppCopyright=tes ...
- Twitter Bootstrap JavaScript插件
Twitter Bootstrap JavaScript插件本文收集了10款非常不错的JavaScript Twitter bootstrap扩展插件,利用Boostrap开发者可以节省大量的时间修复 ...
- 一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10(转载)
在网站开发中不免因为各种兼容问题苦恼,针对兼容问题,其实IE给出了解决方案Google也给出了解决方案百度也应用了这种方案去解决IE的兼容问题 百度源代码如下 <!Doctype html> ...
- C# dll 事件执行 js 回调函数
C# dll 事件执行 js 回调函数 前言: 由于js 远程请求 XMLHttpRequest() 不支持多线程,所以用C# 写了个dll 多线程远程抓住供js调用. 最初代码为: C#代 ...
- HAProxy+apache实现web服务动静分离
HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案. HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支 ...
- 学SpringMVC收藏
一个较完整的SpringMVC工程的配置 2014-01-22 17:17:25 标签:java spring springMVC 配置 springSecurity web.xml 原创作品,允许 ...
- 关于PHP 缓冲区
最权威的资料:http://php.net/manual/en/function.flush.php 里面有全世界的开发者的留言.常见问题都有讨论. 再说一下PHP 缓冲区相关的. web服务器 如 ...
- MVC应用程序请求密码的功能(二)
MVC应用程序请求密码的功能(二) 在完成<MVC应用程序请求密码的功能(一)>http://www.cnblogs.com/insus/p/3471534.html之后,如果你照着做,所 ...