sodu pip3 install Django
python3 -m django --version
1.11.7
django-admin startproject idvip
这将创建一个目录myweb,
sudo python3 manage.py runserver 0:8000
DisallowedHost at /polls
Invalid HTTP_HOST header: '192.168.*.*:8000'. You may need to add '192.168.*.*' to ALLOWED_HOSTS.
HTTP_HOST标头无效:'192.168.*.*:8000'。您可能需要将“192.168.*.*”添加到ALLOWED_HOSTS
解决:
进入 mysite/settings.py文件
ALLOWED_HOSTS = ['192.168.194.132']
然后可以用127.0.0.1:8000进行浏览器访问,出现以下内容表示访问成功
//myhome用于存放前端相关数据
python3 manage.py startapp myhome
//myadmin用于存放后端相关数据
python3 manage.py startapp myadmin
这将创建一个目录myhome和myadmin应用。
并在templates中,创建myadmin和myhome,以用于存放前台和后台页面
在settings.py文件中 TEMPLATES模块设置选项
'DIRS': [os.path.join(BASE_DIR,"templates")],
LANGUAGE_CODE = 'zh-Hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = False
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
sudo apt-get install mysql-server
sudo apt install mysql-client
sudo apt install libmysqlclient-dev
pip3 install pymysql
create database idvip default charset=utf8
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'idvip',#选择数据库的名,请确认你的mysql中有这个库
'USER': 'root',
'PASSWORD': '123456',
'HOST': 'localhost',
'PORT': '3306',
}
}
import pymysql
pymysql.install_as_MySQLdb()
from django.db import models
class Users(models.Model):
username = models.CharField(max_length=20)
password = models.CharField(max_length=77)
phone = models.CharField(max_length=11)
email = models.CharField(max_length=100,null=True)
age = models.IntegerField(default=18)
pic_url = models.CharField(max_length=100,null=True)
SEX_CHOICES = (
(0,'女'),
(1,'男'),
)
sex = models.CharField(max_length=1,null=True,choices=SEX_CHOICES)
status = models.IntegerField(default=0)
addtime = models.DateTimeField(auto_now_add=True)
# 自定义 会员管理 权限
class Meta:
permissions = (
("show_Users","查看用户列表权限"),
("create_Users","添加用户信息权限"),
("edit_Users","修改用户信息权限"),
("remove_Users","删除用户信息权限"),
)
# class Meta:
# db_table = "polls_users" # 指定表名
生成迁移文件
python3 manage.py makemigrations
执行迁移
python3 manage.py migrate
到此,基本环境就已经配置成功了,如果有疏漏,还望提醒。