zoukankan      html  css  js  c++  java
  • django带后台管理功能的网站

    一、原起:

      我大学是学的.Net平台、在那个平台上开发网站用的是ASP.NET这门技术;在那里对数据库的处理、为了

      方便写代码,通常也是会用ORM(对象关系模型映射);毕业后搞起了MySQL数据库、自学了python、到现

      在用起了django、才发现django中比ASP.NET做的还要过分、就是在你定义完ORM后只要对项目进行一点点

      小的改动,那的项目就有后台管理功能了。 下面讲一下django官方文档中的例子

    二、创建project :

    django-admin startproject project3

    三、在project3 项目中创建一个名叫polls 的app:

    python3 manage.py startapp polls

    三、修改polls/models.py 文件增加两表的模型:

     

    四、注测polls到项目:

    五、配置后台数据库:

    六、迁移三中定义好的数据库模型到后台数据库:

    python3 manage.py makemigrations polls
    Migrations for 'polls':
      polls/migrations/0001_initial.py
        - Create model Choice
        - Create model Question
        - Add field question to choice
    JianglexingdeMacBook-Pro:project3 jianglexing$ python3 manage.py migrate
    Operations to perform:
      Apply all migrations: admin, auth, contenttypes, polls, sessions
    Running migrations:
      Applying contenttypes.0001_initial... OK
      Applying auth.0001_initial... OK
      Applying admin.0001_initial... OK
      Applying admin.0002_logentry_remove_auto_add... OK
      Applying contenttypes.0002_remove_content_type_name... OK
      Applying auth.0002_alter_permission_name_max_length... OK
      Applying auth.0003_alter_user_email_max_length... OK
      Applying auth.0004_alter_user_username_opts... OK
      Applying auth.0005_alter_user_last_login_null... OK
      Applying auth.0006_require_contenttypes_0002... OK
      Applying auth.0007_alter_validators_add_error_messages... OK
      Applying auth.0008_alter_user_username_max_length... OK
      Applying polls.0001_initial... OK
      Applying sessions.0001_initial... OK

    七、把数据库模型注测到admin网站:

    八、创建admin用户:

     python3 manage.py createsuperuser
    Username (leave blank to use 'jianglexing'): admin
    Email address: 1721900707@qq.com
    Password:
    Password (again):
    Superuser created successfully.

    九、启动django项目:

    python3 manage.py runserver 127.0.0.1:8080
    Performing system checks...
    
    System check identified no issues (0 silenced).
    November 18, 2017 - 02:55:21
    Django version 1.11.7, using settings 'project3.settings'
    Starting development server at http://127.0.0.1:8080/
    Quit the server with CONTROL-C.

    十、从web访问:

    ----

  • 相关阅读:
    iTerm2分屏快捷键
    k8s中运维/测试常用的命令整理(随时更新)
    httpRunner自动化测试用例使用笔记
    Git学习笔记-快速上手(mac系统)
    RBAC权限控制逻辑笔记
    CPS中有关CICD的配置
    LDAP中filter的使用
    Docker初级入门
    C语言 实现 HashTable
    从三个线程 排队打印 , 到 多个线程打印
  • 原文地址:https://www.cnblogs.com/JiangLe/p/7853174.html
Copyright © 2011-2022 走看看