Browse Source

添加后台server

wangwei 4 years ago
parent
commit
16fde14cc1
48 changed files with 787 additions and 0 deletions
  1. 5 0
      README.md
  2. 0 0
      server/api/__init__.py
  3. BIN
      server/api/__pycache__/__init__.cpython-38.pyc
  4. BIN
      server/api/__pycache__/admin.cpython-38.pyc
  5. BIN
      server/api/__pycache__/models.cpython-38.pyc
  6. BIN
      server/api/__pycache__/urls.cpython-38.pyc
  7. BIN
      server/api/__pycache__/views.cpython-38.pyc
  8. 3 0
      server/api/admin.py
  9. 5 0
      server/api/apps.py
  10. 45 0
      server/api/form.py
  11. 41 0
      server/api/migrations/0001_initial.py
  12. 38 0
      server/api/migrations/0002_auto_20210325_1617.py
  13. 33 0
      server/api/migrations/0003_auto_20210325_1630.py
  14. 18 0
      server/api/migrations/0004_auto_20210325_1634.py
  15. 18 0
      server/api/migrations/0005_auto_20210325_1641.py
  16. 18 0
      server/api/migrations/0006_auto_20210325_1644.py
  17. 18 0
      server/api/migrations/0007_auto_20210325_1649.py
  18. 18 0
      server/api/migrations/0008_auto_20210325_1650.py
  19. 18 0
      server/api/migrations/0009_user_status.py
  20. 35 0
      server/api/migrations/0010_auto_20210326_1006.py
  21. 23 0
      server/api/migrations/0011_auto_20210329_1145.py
  22. 0 0
      server/api/migrations/__init__.py
  23. BIN
      server/api/migrations/__pycache__/0001_initial.cpython-38.pyc
  24. BIN
      server/api/migrations/__pycache__/0002_auto_20210325_1617.cpython-38.pyc
  25. BIN
      server/api/migrations/__pycache__/0003_auto_20210325_1630.cpython-38.pyc
  26. BIN
      server/api/migrations/__pycache__/0004_auto_20210325_1634.cpython-38.pyc
  27. BIN
      server/api/migrations/__pycache__/0005_auto_20210325_1641.cpython-38.pyc
  28. BIN
      server/api/migrations/__pycache__/0006_auto_20210325_1644.cpython-38.pyc
  29. BIN
      server/api/migrations/__pycache__/0007_auto_20210325_1649.cpython-38.pyc
  30. BIN
      server/api/migrations/__pycache__/0008_auto_20210325_1650.cpython-38.pyc
  31. BIN
      server/api/migrations/__pycache__/0009_user_status.cpython-38.pyc
  32. BIN
      server/api/migrations/__pycache__/0010_auto_20210326_1006.cpython-38.pyc
  33. BIN
      server/api/migrations/__pycache__/0011_auto_20210329_1145.cpython-38.pyc
  34. BIN
      server/api/migrations/__pycache__/__init__.cpython-38.pyc
  35. 47 0
      server/api/models.py
  36. 3 0
      server/api/tests.py
  37. 28 0
      server/api/urls.py
  38. 161 0
      server/api/views.py
  39. 22 0
      server/manage.py
  40. 2 0
      server/server/__init__.py
  41. BIN
      server/server/__pycache__/__init__.cpython-38.pyc
  42. BIN
      server/server/__pycache__/settings.cpython-38.pyc
  43. BIN
      server/server/__pycache__/urls.cpython-38.pyc
  44. BIN
      server/server/__pycache__/wsgi.cpython-38.pyc
  45. 16 0
      server/server/asgi.py
  46. 136 0
      server/server/settings.py
  47. 20 0
      server/server/urls.py
  48. 16 0
      server/server/wsgi.py

+ 5 - 0
README.md

@@ -14,6 +14,11 @@
 - [ ] 在`.env[xxx]`文件中修改相关项目配置
 - [ ] 在`src/settings/projectSetting.ts`内调整适合自己的项目风格
 
+## server django 后台启动
+
+- cd server
+- py manage.py runserver `默认端口8000`
+
 ## 注意
 
 依赖删除了`echarts`,`apexcharts`,`xlsx`,`vditor`。但是组件及代码未删除。在你未引用到相关组件的时候,不会发出错误。当你需要使用的时候,只需要执行相应的命令安装对应模块即可

+ 0 - 0
server/api/__init__.py


BIN
server/api/__pycache__/__init__.cpython-38.pyc


BIN
server/api/__pycache__/admin.cpython-38.pyc


BIN
server/api/__pycache__/models.cpython-38.pyc


BIN
server/api/__pycache__/urls.cpython-38.pyc


BIN
server/api/__pycache__/views.cpython-38.pyc


+ 3 - 0
server/api/admin.py

@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.

+ 5 - 0
server/api/apps.py

@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class ApiConfig(AppConfig):
+    name = 'api'

+ 45 - 0
server/api/form.py

@@ -0,0 +1,45 @@
+# -*- encoding: utf-8 -*-
+'''
+@Desc    :   用户自定义表单
+@File    :   form.py
+@Time    :   2021/03/26 12:23:15
+@Author  :   wang
+@Version :   1.0
+'''
+
+# here put the import lib
+
+from django import forms
+from django.core.exceptions import ValidationError
+
+class MenuForm(forms.Form):
+  path = forms.CharField(required=True,error_messages={
+    'required':'路径必须输入',
+  })
+  name = forms.CharField(required=True,error_messages={
+    'required':'路径名必须输入',
+  })
+  component = forms.CharField(required=True,error_messages={
+    'required':'组件路径必须输入',
+  })
+  title = forms.CharField(required=True,error_messages={
+    'required':'菜单名必须输入',
+  })
+  # icon = forms.CharField(required=True,error_messages={
+  #   'required':'菜单图标必须输入',
+  # })
+
+  # # 单个字段验证 clean_xxx
+  # def clean_password(self):
+  #   password = self.cleaned_data.get('password')
+  #   if password and password.isdigit():
+  #     raise ValidationError("密码不能是纯数字")
+  #   return password
+
+  # # 全局验证
+  # def clean(self):
+  #   password = self.cleaned_data.get('password',None)
+  #   confirm = self.cleaned_data.get('confirm',None)
+  #   if password != confirm:
+  #     raise ValidationError({'confirm':"两次密码输入不一致"})
+  #   return self.cleaned_data

+ 41 - 0
server/api/migrations/0001_initial.py

@@ -0,0 +1,41 @@
+# Generated by Django 3.1.7 on 2021-03-25 15:36
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='User',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('username', models.CharField(max_length=16)),
+                ('password', models.CharField(max_length=32)),
+                ('desc', models.CharField(max_length=124)),
+                ('token', models.CharField(max_length=500)),
+            ],
+        ),
+        migrations.CreateModel(
+            name='Menu',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('path', models.CharField(blank=True, max_length=64, null=True)),
+                ('name', models.CharField(max_length=64, verbose_name='菜单名称')),
+                ('component', models.CharField(blank=True, max_length=512, null=True)),
+                ('redirect', models.CharField(blank=True, max_length=64, null=True)),
+                ('remark', models.CharField(blank=True, max_length=64, null=True)),
+                ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='api.menu')),
+            ],
+            options={
+                'verbose_name': '菜单',
+                'verbose_name_plural': '菜单',
+            },
+        ),
+    ]

+ 38 - 0
server/api/migrations/0002_auto_20210325_1617.py

@@ -0,0 +1,38 @@
+# Generated by Django 3.1.7 on 2021-03-25 16:17
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Metas',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('title', models.CharField(max_length=32)),
+                ('affix', models.BooleanField(default=True)),
+                ('icon', models.CharField(max_length=32)),
+            ],
+        ),
+        migrations.AddField(
+            model_name='menu',
+            name='users',
+            field=models.ManyToManyField(null=True, to='api.User'),
+        ),
+        migrations.AlterField(
+            model_name='user',
+            name='username',
+            field=models.CharField(max_length=20),
+        ),
+        migrations.AddField(
+            model_name='menu',
+            name='meta',
+            field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.metas'),
+        ),
+    ]

+ 33 - 0
server/api/migrations/0003_auto_20210325_1630.py

@@ -0,0 +1,33 @@
+# Generated by Django 3.1.7 on 2021-03-25 16:30
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0002_auto_20210325_1617'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='user',
+            name='realname',
+            field=models.CharField(max_length=20, null=True),
+        ),
+        migrations.AlterField(
+            model_name='user',
+            name='password',
+            field=models.CharField(max_length=32, unique=True),
+        ),
+        migrations.AlterField(
+            model_name='user',
+            name='token',
+            field=models.CharField(max_length=500, unique=True),
+        ),
+        migrations.AlterField(
+            model_name='user',
+            name='username',
+            field=models.CharField(max_length=20, unique=True),
+        ),
+    ]

+ 18 - 0
server/api/migrations/0004_auto_20210325_1634.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.1.7 on 2021-03-25 16:34
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0003_auto_20210325_1630'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='user',
+            name='password',
+            field=models.CharField(max_length=32),
+        ),
+    ]

+ 18 - 0
server/api/migrations/0005_auto_20210325_1641.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.1.7 on 2021-03-25 16:41
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0004_auto_20210325_1634'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='metas',
+            name='affix',
+            field=models.BooleanField(default='true'),
+        ),
+    ]

+ 18 - 0
server/api/migrations/0006_auto_20210325_1644.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.1.7 on 2021-03-25 16:44
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0005_auto_20210325_1641'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='metas',
+            name='affix',
+            field=models.BooleanField(default=True),
+        ),
+    ]

+ 18 - 0
server/api/migrations/0007_auto_20210325_1649.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.1.7 on 2021-03-25 16:49
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0006_auto_20210325_1644'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='metas',
+            name='affix',
+            field=models.BooleanField(default=False),
+        ),
+    ]

+ 18 - 0
server/api/migrations/0008_auto_20210325_1650.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.1.7 on 2021-03-25 16:50
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0007_auto_20210325_1649'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='metas',
+            name='affix',
+            field=models.BooleanField(default=True),
+        ),
+    ]

+ 18 - 0
server/api/migrations/0009_user_status.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.1.7 on 2021-03-25 17:52
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0008_auto_20210325_1650'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='user',
+            name='status',
+            field=models.BooleanField(default=1),
+        ),
+    ]

+ 35 - 0
server/api/migrations/0010_auto_20210326_1006.py

@@ -0,0 +1,35 @@
+# Generated by Django 3.1.7 on 2021-03-26 10:06
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0009_user_status'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='menu',
+            name='meta',
+        ),
+        migrations.AddField(
+            model_name='menu',
+            name='affix',
+            field=models.BooleanField(default=1),
+        ),
+        migrations.AddField(
+            model_name='menu',
+            name='icon',
+            field=models.CharField(max_length=32, null=True),
+        ),
+        migrations.AddField(
+            model_name='menu',
+            name='title',
+            field=models.CharField(max_length=32, null=True),
+        ),
+        migrations.DeleteModel(
+            name='Metas',
+        ),
+    ]

+ 23 - 0
server/api/migrations/0011_auto_20210329_1145.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.1.7 on 2021-03-29 11:45
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0010_auto_20210326_1006'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='user',
+            name='roleName',
+            field=models.CharField(max_length=32, null=True),
+        ),
+        migrations.AddField(
+            model_name='user',
+            name='value',
+            field=models.CharField(max_length=32, null=True),
+        ),
+    ]

+ 0 - 0
server/api/migrations/__init__.py


BIN
server/api/migrations/__pycache__/0001_initial.cpython-38.pyc


BIN
server/api/migrations/__pycache__/0002_auto_20210325_1617.cpython-38.pyc


BIN
server/api/migrations/__pycache__/0003_auto_20210325_1630.cpython-38.pyc


BIN
server/api/migrations/__pycache__/0004_auto_20210325_1634.cpython-38.pyc


BIN
server/api/migrations/__pycache__/0005_auto_20210325_1641.cpython-38.pyc


BIN
server/api/migrations/__pycache__/0006_auto_20210325_1644.cpython-38.pyc


BIN
server/api/migrations/__pycache__/0007_auto_20210325_1649.cpython-38.pyc


BIN
server/api/migrations/__pycache__/0008_auto_20210325_1650.cpython-38.pyc


BIN
server/api/migrations/__pycache__/0009_user_status.cpython-38.pyc


BIN
server/api/migrations/__pycache__/0010_auto_20210326_1006.cpython-38.pyc


BIN
server/api/migrations/__pycache__/0011_auto_20210329_1145.cpython-38.pyc


BIN
server/api/migrations/__pycache__/__init__.cpython-38.pyc


+ 47 - 0
server/api/models.py

@@ -0,0 +1,47 @@
+from django.db import models
+
+
+class User(models.Model):
+    username = models.CharField(max_length=20, unique=True, null=False)
+    realname = models.CharField(max_length=20, null=True)
+    password = models.CharField(max_length=32, null=False)
+    roleName = models.CharField(max_length=32, null=True)
+    value = models.CharField(max_length=32, null=True)
+    status = models.BooleanField(default=1)
+    desc = models.CharField(max_length=124)
+    token = models.CharField(max_length=500, unique=True, null=False)
+
+    def __unicode__(self):
+        return self.username
+
+# class Metas(models.Model):
+  # title = models.CharField(max_length=32)
+  # affix = models.BooleanField(default=1)
+  # icon = models.CharField(max_length=32)
+
+
+class Menu(models.Model):
+    path = models.CharField(max_length=64, blank=True, null=True)  # 映射数据路径
+    name = models.CharField(max_length=64, verbose_name="菜单名称")  # 菜单名称
+    component = models.CharField(
+        max_length=512, null=True, blank=True)  # view页面路径
+    parent = models.ForeignKey(
+        "Menu", on_delete=models.DO_NOTHING, null=True, blank=True)  # 父节点
+    redirect = models.CharField(max_length=64, null=True, blank=True)  # 重定向
+    remark = models.CharField(max_length=64, null=True, blank=True)  # 备注
+    # meta = models.OneToOneField(Metas,null=True,on_delete=models.CASCADE)
+    users = models.ManyToManyField("User", null=True)
+    # 已下三个为菜单meta配置
+    title = models.CharField(max_length=32, null=True)
+    affix = models.BooleanField(default=1)
+    icon = models.CharField(max_length=32, null=True)
+
+    def __unicode__(self):
+        return self.name
+
+    def __str__(self):
+        return self.name
+
+    class Meta():
+        verbose_name = "菜单"
+        verbose_name_plural = verbose_name

+ 3 - 0
server/api/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 28 - 0
server/api/urls.py

@@ -0,0 +1,28 @@
+# -*- encoding: utf-8 -*-
+'''
+@Desc    :
+@File    :   urls.py
+@Time    :   2021/03/24 10:10:25
+@Author  :   wang
+@Version :   1.0
+'''
+
+# here put the import lib
+
+from django.urls import path
+from . import views
+
+app_name = 'api'  # namespace 命名空间
+
+# 路由列表 urlpatterns
+urlpatterns = [
+    # 不能以/ 开头
+    path('', views.index, name='index'),
+    # path('cbv/', views.cbv.as_view(), name='cbv'),
+    # path('excbv/', views.extend_cbv.as_view(), name='extend_cbv'),
+    path('login/', views.login.as_view(), name='login'),
+    path('getUserInfoById/', views.getUserInfoById.as_view(), name='get_userinfo'),
+    path('user/add/', views.add_user.as_view(), name='add_user'),
+    path('getMenuListById/', views.getMenuListById.as_view(), name='get_menu'),
+    path('menu/add/', views.add_menu.as_view(), name='add_menu'),
+]

+ 161 - 0
server/api/views.py

@@ -0,0 +1,161 @@
+from django.shortcuts import render, redirect, HttpResponse
+from django.http import JsonResponse, HttpResponseRedirect
+from django.views.generic import View
+# from . import models
+from .models import User, Menu
+from django.core.serializers import serialize
+import json
+
+
+# Create your views here.
+
+def index(request):
+    data = {
+        'name': {
+            'firstname': 'Tom',
+            'lastname': 'john'
+        },
+        'age': 18,
+        'sex': '男'
+    }
+    return JsonResponse(data, json_dumps_params={"ensure_ascii": False})
+
+# class cbv(View):
+#   def get(self,request):
+#     print(request)
+#     print(request.GET.get('username'))
+#     return JsonResponse({'method':'get','data':request.GET})
+
+#   def post(self,request):
+#     return JsonResponse({'method':'post','data':request.POST})
+#   def put(self,request):
+#     return JsonResponse({'method':'put'})
+#   def delete(self,request):
+#     return JsonResponse({'method':'delete'})
+
+# class extend_cbv(cbv):
+#   # 重写post请求
+#   def post(self,request):
+#     return JsonResponse({'method':'post','msg':'重写post请求'},json_dumps_params={"ensure_ascii":False})
+
+
+def format_useinfo(user):
+    format_user = json.loads(
+        serialize('json', user, ensure_ascii=False)
+    )
+    for item in format_user:
+        res = item.get('fields')
+        res['userId'] = item.get('pk')
+        res['roles'] = [
+            {
+                'roleName': res.get('roleName'), 'value': res.get('value')
+            }
+        ]
+        res.pop('roleName')
+        res.pop('value')
+    return res
+
+
+def format_menus(data):
+    # 一级菜单列表(无父id)
+    menus = []
+    # 子菜单列表
+    childrens = []
+    for item in data:
+        item['fields']['id'] = item.get('pk')
+        # 将某些字段合并处理成前台需要的路由结构
+        item['fields']['meta'] = {
+            "title": item.get('fields').get('title'),
+            "affix": item.get('fields').get('affix'),
+            "icon": item.get('fields').get('icon'),
+        }
+        # 删除多余字段
+        item['fields'].pop('title')
+        item['fields'].pop('affix')
+        item['fields'].pop('icon')
+        if (item.get('fields').get('parent') == None):
+            menus.append(item.get('fields'))
+        else:
+            childrens.append(item.get('fields'))
+
+    for children in childrens:
+        # 将列表转化成树形菜单
+        getTree(children, menus, childrens)
+    return menus
+
+
+"""
+def getTree(children, menus, childrens)
+根据传递过来的父菜单id,递归设置各层次父菜单的子菜单列表
+:children: 单个子菜单
+:param menus: 父菜单列表 一级菜单
+:childrens: 子菜单列表,第二次调用
+"""
+
+
+def getTree(children, menus, childrens):
+    # 遍历父菜单
+    for m in menus:
+        # 当前菜单的id 和 子菜单的父id 是否匹配
+        if m.get('id') == children.get('parent'):
+            if not m.get('children'):
+                m['children'] = []
+            if not children in m['children']:  # 判单子菜单是否已存在
+                m['children'].append(children)
+
+            if m.get('children'):
+                for children in childrens:
+                    # 判断子菜单是否还有匹配的子菜单
+                    getTree(children, m.get('children'), childrens)
+
+
+class login(View):
+
+    def post(self, request):
+        data = json.loads(request.body)
+        user = User.objects.all().filter(username=data.get(
+            'username'), password=data.get('password'))
+        if user:
+            res = format_useinfo(user)
+            return JsonResponse({'code': 0, 'msg': 'success', 'result': res}, json_dumps_params={"ensure_ascii": False})
+        else:
+            return JsonResponse({'code': 1, 'error': '用户名或密码不正确'}, json_dumps_params={"ensure_ascii": False})
+
+
+class getUserInfoById(View):
+    def get(self, request):
+        userid = request.GET.get('userId')
+        user = User.objects.all().filter(id=userid)
+        if user:
+            # res = {'codeList': ['1000', '3000', '5000']}
+            res = format_useinfo(user)
+            return JsonResponse({'code': 0, 'result': res, })
+        else:
+            return JsonResponse({'code': 1, 'result': {'message': 'error'}}, json_dumps_params={"ensure_ascii": False})
+
+
+class add_user(View):
+    def post(self, request):
+        data = request.POST
+        if User.objects.all().filter(username=data.get('username')):
+            return JsonResponse({'code': 0, 'error': '该角色名已被创建'})
+        else:
+            User.objects.create(**data)
+            return JsonResponse({'code': 1, 'data': '角色创建成功'})
+
+
+class getMenuListById(View):
+    def get(self, request):
+        querySetObj = Menu.objects.all()
+
+        # querySet 转json对象
+        data = json.loads(serialize('json', querySetObj, ensure_ascii=False))
+        menus = format_menus(data)
+        return JsonResponse({'code': 0, 'result': menus})
+
+
+class add_menu(View):
+    def post(self, request):
+        data = request.POST
+        Menu.objects.create(**data)
+        return JsonResponse({'code': 1, 'error': '菜单添加成功'})

+ 22 - 0
server/manage.py

@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+"""Django's command-line utility for administrative tasks."""
+import os
+import sys
+
+
+def main():
+    """Run administrative tasks."""
+    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'server.settings')
+    try:
+        from django.core.management import execute_from_command_line
+    except ImportError as exc:
+        raise ImportError(
+            "Couldn't import Django. Are you sure it's installed and "
+            "available on your PYTHONPATH environment variable? Did you "
+            "forget to activate a virtual environment?"
+        ) from exc
+    execute_from_command_line(sys.argv)
+
+
+if __name__ == '__main__':
+    main()

+ 2 - 0
server/server/__init__.py

@@ -0,0 +1,2 @@
+import pymysql
+pymysql.install_as_MySQLdb()

BIN
server/server/__pycache__/__init__.cpython-38.pyc


BIN
server/server/__pycache__/settings.cpython-38.pyc


BIN
server/server/__pycache__/urls.cpython-38.pyc


BIN
server/server/__pycache__/wsgi.cpython-38.pyc


+ 16 - 0
server/server/asgi.py

@@ -0,0 +1,16 @@
+"""
+ASGI config for server project.
+
+It exposes the ASGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
+"""
+
+import os
+
+from django.core.asgi import get_asgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'server.settings')
+
+application = get_asgi_application()

+ 136 - 0
server/server/settings.py

@@ -0,0 +1,136 @@
+"""
+Django settings for server project.
+
+Generated by 'django-admin startproject' using Django 3.1.7.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.1/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/3.1/ref/settings/
+"""
+
+from pathlib import Path
+
+# Build paths inside the project like this: BASE_DIR / 'subdir'.
+BASE_DIR = Path(__file__).resolve().parent.parent
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'b06y0-4h3ao9mdkdfn0r^1@!9r6)&8-q*!f8q_^1hvrw=ri95_'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Application definition
+
+INSTALLED_APPS = [
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.messages',
+    'django.contrib.staticfiles',
+    'api',
+    'corsheaders'
+]
+
+MIDDLEWARE = [
+    'django.middleware.security.SecurityMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'corsheaders.middleware.CorsMiddleware',  # 添加跨域中间件,需注意顺序
+    'django.middleware.common.CommonMiddleware',
+    # 'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+]
+CORS_ALLOW_CREDENTIALS = True
+CORS_ORIGIN_ALLOW_ALL = True
+# 指定白名单
+# CORS_ORIGIN_WHITELIST = (
+#     'http://google.com',
+#     'http://hostname.example.com',
+#     'http://localhost:8000',
+#     'http://127.0.0.1:9000'
+# )
+
+ROOT_URLCONF = 'server.urls'
+
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'DIRS': [],
+        'APP_DIRS': True,
+        'OPTIONS': {
+            'context_processors': [
+                'django.template.context_processors.debug',
+                'django.template.context_processors.request',
+                'django.contrib.auth.context_processors.auth',
+                'django.contrib.messages.context_processors.messages',
+            ],
+        },
+    },
+]
+
+WSGI_APPLICATION = 'server.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.mysql',
+        'NAME': 'ant_backend',  # 数据库名
+        'HOST': '127.0.0.1',
+        'USER': 'root',
+        'PASSWORD': 'password',
+        'PORT': 3306
+    }
+}
+
+
+# Password validation
+# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+    {
+        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+    },
+]
+
+
+# Internationalization
+# https://docs.djangoproject.com/en/3.1/topics/i18n/
+
+LANGUAGE_CODE = 'zh-hans'
+
+TIME_ZONE = 'Asia/Shanghai'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = False
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/3.1/howto/static-files/
+
+STATIC_URL = '/static/'

+ 20 - 0
server/server/urls.py

@@ -0,0 +1,20 @@
+"""server URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+    https://docs.djangoproject.com/en/3.1/topics/http/urls/
+Examples:
+Function views
+    1. Add an import:  from my_app import views
+    2. Add a URL to urlpatterns:  path('', views.home, name='home')
+Class-based views
+    1. Add an import:  from other_app.views import Home
+    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
+Including another URLconf
+    1. Import the include() function: from django.urls import include, path
+    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
+"""
+from django.urls import path,include
+
+urlpatterns = [
+    path('api/', include('api.urls')),
+]

+ 16 - 0
server/server/wsgi.py

@@ -0,0 +1,16 @@
+"""
+WSGI config for server project.
+
+It exposes the WSGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'server.settings')
+
+application = get_wsgi_application()