1.新建django项目newnet
2021-03-08 15:28
标签:create mysqld efault Edito character ase har ken 图片 虚拟环境选个能用的 打开mysql终端: 1.在settings.py中: 2.安装PyMYSQL: 3.在newnet/newnet/__init__.py中加代码: 1.新建app:good、trade、user_operation 2.在settings.py中配置app: 1.新建两个目录 2.在settings中配置路径: 3.在newnet/urls.py中配置媒体文件路径: 1.新建apps包用来存放我们新建的app,将users、good、trade、user_operation拖入。 2.新建extra_apps包,用来存放第三方包。 3.mark路径(apps和extra_apps都要mark) 3.settings中配置: 4.导入第三方包xadmin和DjangoUeditor 1.新建django项目newnet 标签:create mysqld efault Edito character ase har ken 图片 原文地址:https://www.cnblogs.com/xuepangzi/p/12874008.html1.新建项目newnet,新建app:users:
2.新建mysql数据库newnet:
show databases; --查看所有数据库
create database newnet default character set utf8 collate utf8_general_ci; --创建数据库gg,因为创建数据表内有中文字段,所以要加default
show databases; --查看所有数据库
3.连接数据库:
DATABASES = {
‘default‘: {
‘ENGINE‘: ‘django.db.backends.mysql‘,
‘NAME‘: ‘newnet‘,
‘USER‘:‘root‘,
‘PASSWORD‘:‘数据库密码‘,
‘HOST‘:‘127.0.0.1‘,
"OPTIONS":{"init_command":"SET default_storage_engine=INNODB;"}#第三方登录功能必须加上
}
}
pip install PyMYSQL
import pymysql
pymysql.install_as_MySQLdb()
4.新建app
python manage.py startapp good
python manage.py startapp trade
python manage.py startapp user_operation
INSTALLED_APPS = [
‘django.contrib.admin‘,
‘django.contrib.auth‘,
‘django.contrib.contenttypes‘,
‘django.contrib.sessions‘,
‘django.contrib.messages‘,
‘django.contrib.staticfiles‘,
‘users.apps.UsersConfig‘,
‘good.apps.GoodConfig‘,
‘trade.apps.TradeConfig‘,
‘user_operation.apps.UserOperationConfig‘
]
5.新建目录 静态文件目录static,媒体文件目录media:
STATIC_URL = ‘/static/‘
STATIC_ROOT = os.path.join(BASE_DIR, ‘static‘)
MEDIA_URL=‘/media/‘
MEDIA_ROOT=os.path.join(BASE_DIR,‘media‘)
from django.contrib import admin
from django.urls import path
from django.views.static import serve
from newnet.settings import MEDIA_ROOT
urlpatterns = [
path(‘admin/‘, admin.site.urls),
path(‘media/
6.整理项目目录:
import sys
sys.path.insert(0,BASE_DIR)
sys.path.insert(0,os.path.join(BASE_DIR,‘apps‘))
sys.path.insert(0,os.path.join(BASE_DIR,‘extra_apps‘))