New jangostart project
New manager.py i.e. using a separate application app
Create a message application
manage.py@djangostart > startapp message
If the new app and more are under djangostart, in order to distinguish between apps, new apps directory message will be dragged into the apps folder
Need to introduce message
From apps.message import views, if that trouble may be apps source root
Django into the project directory, run reports an error
(Testvir2) D: \ python \ djangostart>
Source root configuration settings in the
Install mysql driver
(testvir2) D:\python\djangostart>pip install mysql-python
Error: Download the Driver
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
Download MySQL_python-1.2.5-cp27-none-win_amd64.whl copy of the current directory to a virtual environment
Run the installation
If you want to develop python3 need mysqlclient, in fact, the interface is the same
Configuration templates relative path: configuration settings file
'DIRS': [os.path.join(BASE_DIR, 'templates')],
Error fetching command 'collectstatic': You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
Command 'collectstatic' skipped
把static目录加入settings.py配置文件中否则css样式无法正常加载
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ]
使用manage.py生成django默认表结构
makemigrations
migrate
设计关于留言板message的models
Settings文件中注册apps.message
# _*_ coding:utf-8 from __future__ import unicode_literals from django.db import models # Create your models here. class UserMessage(models.Model): name = models.CharField(max_length=20, verbose_name=u"用户名") email = models.EmailField(verbose_name=u"邮箱") address = models.CharField(max_length=100, verbose_name=u"联系地址") message = models.CharField(max_length=500, verbose_name=u"留言信箱") class Meta: verbose_name = u"用户留言信箱"
根据models生成表
makemigrations message
migrate message
查看表结构