实现用户注册与登录、登出(二)
来源:互联网 发布:bartender vb脚本示例 编辑:程序博客网 时间:2024/05/18 02:32
扩展资料后的用户判断
在后台添加用户资料的模型,在前端页面添加用户判断的条件
M
从models中引入User建立UserProfile模型(用户资料模型)
from django.db import modelsfrom faker import Factoryfrom django.contrib.auth.models import User# Create your models here.class Video(models.Model): title = models.CharField(null=True, blank=True, max_length=300) content = models.TextField(null=True, blank=True) url_image = models.URLField(null=True, blank=True) cover = models.FileField(upload_to='cover_image', null=True) editors_choice = models.BooleanField(default=False) def __str__(self): return self.titleclass UserProfile(models.Model): belong_to = models.OneToOneField(to=User, related_name='profile') profile_image = models.FileField(upload_to='profile_image')# f = open('/Users/Hou/Desktop/web_url.txt','r')# for url in f.readlines():# v = Video(# title=fake.text(max_nb_chars=90),# content=fake.text(max_nb_chars=3000),# url_image=url,# editors_choice=fake.pybool()# )# v.save()
admin.py
在admin.py中注册模型
from django.contrib import adminfrom website.models import Video, UserProfile# Register your models here.admin.site.register(Video)admin.site.register(UserProfile)
MM
T
列表页面通过判断显示正在登录的用户头像
<div class="item"> <h5 class="ui inverted header"> <span style="margin-right:20px;">{{ request.user.username }}</span> <div class="ui mini circular image"> {% if request.user.profile.profile_image %} <img src="/upload/{{ request.user.profile.profile_image }}" alt="" /> {% else %} <img src="http://semantic-ui.com/images/avatar/small/matt.jpg" alt="" /> {% endif %} </div> </h5> </div>
{% load staticfiles %}<!DOCTYPE html><html><head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href="{% static 'css/semantic.css' %}" media="screen" title="no title" charset="utf-8"> <link rel="stylesheet" href="{% static 'css/list_custom.css' %}" media="screen" title="no title" charset="utf-8"></head><body> <div class="ui inverted top fixed menu borderless red menu"> <div class="header item"> <div class="ui image"> <img src="{% static 'images/tenlogo.png' %}" alt=""> </div> </div> <div class="right menu"> {% if request.user.is_authenticated %} <div class="item"> <h5 class="ui inverted header"> <span style="margin-right:20px;">{{ request.user.username }}</span> <div class="ui mini circular image"> {% if request.user.profile.profile_image %} <img src="/upload/{{ request.user.profile.profile_image }}" alt="" /> {% else %} <img src="http://semantic-ui.com/images/avatar/small/matt.jpg" alt="" /> {% endif %} </div> </h5> </div> <div class="item"> <a href="#" class="ui inverted circular button">Logout</a> </div> {% else %} <div class="item"> <h5 class="ui inverted header"> <span style="margin-right:20px">{{ request.user.username }}</span> <div class="ui mini circular image"> <img src="http://semantic-ui.com/images/avatar/small/matt.jpg" alt="" /> </div> </h5> </div> <div class="item"> <a href="#" class="ui inverted circular button">Signup/Login</a> </div> {% endif %} </div> </div> <div class="ui inverted segment container nav"> <div class="ui three borderless item menu"> <a class="item" > All </a> <a class="item"> New </a> {% if 'editors' in request.path %} <a class="active item" href="{% url 'list' %}editors"> Editor's </a> {% else %} <a class="item" href="{% url 'list' %}editors"> Editor's </a> {% endif %} </div> </div> <div class="ui basic segment container content"> <div class="ui three column grid"> {% for article in vids_list %} <div class="column"> <a class="ui fluid card" href="{% url 'list' %}"> <div class="image"> {% if article.cover %} <img src="/upload/{{ article.cover }}" alt="" style="height:200px;object-fit: cover;"> {% else %} <img src="{{ article.url_image }}" alt="" style="height:200px;object-fit: cover;"> {% endif %} </div> </a> <div class="title header" href="{% url 'list' %}">{{ article.title }}</div> <i class="icon grey unhide"></i> <span style="color:#bbbbbb">{{ article.views }}</span> <span class="" style="color:rgb(226, 226, 226)">|</span> <i class="icon grey checkmark"></i> <span style="color:#bbbbbb"> {{ article.favs }} people got it</span> </div> {% endfor %} </div> </div> <div class="ui center aligned very padded vertical segment container"> <div class="ui pagination menu"> {% if vids_list.has_previous %} <a href="?page={{ vids_list.previous_page_number }}" class="item"> <i class="icon red left arrow"></i> </a> {% else %} <a href="?page={{ vids_list.start_index }}" class="disabled item"> <i class="icon left arrow"></i> </a> {% endif %} {% if vids_list.has_next %} <a href="?page={{ vids_list.next_page_number }}" class="item"> <i class="icon red right arrow"></i> </a> {% else %} <a href="?page={{ vids_list.end_index }}" class="disabled item"> <i class="icon right arrow"></i> </a> {% endif %} </div> </div></body></html>
阅读全文
0 0
- 实现用户注册与登录、登出(二)
- 实现用户注册与登录、登出(一)
- 实现用户注册与登录、登出(三)
- 使用Forms Authentication实现用户注册、登录 (二)用户注册与登录
- APICloud技巧 | 用户登录与登出的实现方法
- 实现PHP用户的注册与登录
- 实现PHP用户的注册与登录 .
- 用户注册与登录功能的实现
- 单点登录(二)使用Cookie+File实现单点登录登出(附源码)
- django 登录与登出
- 网站用户登录注册实现
- 用纯jsp实现用户的登录、注册与退出
- struts2连接数据库实现用户注册与登录
- java 与数据库连接 实现用户的注册和登录
- java 与数据库连接 实现用户的注册和登录
- PHP 用户注册与登录
- Struts2+Spring+iBatis整合用户管理实例之二:登录和登出
- Struts2+Spring+iBatis整合用户管理实例之二:登录和登出
- # main java.lang.StackOverflowError
- cin.get();cin.getline();getline(cin,string);cin.ignore()的理解
- HTTPS与http
- OpenCV学习笔记(24)关于hough变换中pt1、pt2点的确定
- xutil
- 实现用户注册与登录、登出(二)
- mysql中表设置了外键关联,可以语句强制更新
- 【Struts2】Struts2学习(6)文件上传和下载
- 编码中的setCharacterEncoding 理解
- call和apply
- 树的表示方法
- codeforces—— 476A —— Dreamoon and Stairs
- SVN管理项目时拷贝注意
- JS之四舍五入Fixed