0 NewProj
01 将source_data材料包放到项目根目录。将其中的static文件夹剪切到根目录。将剩下的temps文件剪切到templates文件夹下。可删source_data。后续用默认sqlite。
STATIC_URL = "/static/"
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
02 python manage.py startapp product。python manage.py startapp users 。python manage.py startapp orders。安装、路由链接。users下temp/usr与login html。
1 users_app (① 登录 退出 ② 登录后登录注册按钮显示为用户名 ③ 点击用户名跳转至用户账户页面)
11 models 迁移
from django.db import models
class User(models.Model):
user_name = models.CharField(max_length=32, unique=True)
password = models.CharField(max_length=128)
token = models.CharField(max_length=128, null=True)
class Meta:
db_table = 'users'
@classmethod
def get_list(cls, **kwargs):
filters = {} # 赋值等号有空格,传参等号无空格
if kwargs.get('user_name'):
filters['user_name'] = kwargs.get('user_name')
if kwargs.get('password'):
filters['password'] = kwargs.get('password')
return cls.objects.filter(**filters)
@classmethod
def create_one(cls, user_name, password):
return cls.objects.create(user_name=user_name, password=password)
@classmethod
def get_one(cls, pk):
try:
return cls.objects.get(pk=pk)
except cls.DoesNotExist:
return None
12 html调整
{% load static %}
herf ="{% static 'xxx.cssjsjpgpng'%}"