• Django 系列1:Django简介


    1、Django MTV框架

    MVC



    MTV


    2、安装


    虚拟环境

    pip install Django==2.2.9



    3、创建工程

    django-admin startproject HelloDjango

    python mange.py startapp App

    er

    python mange.py runserver

    Django自带内置了一个开发者服务器,性能比较低,上线以后不能用runserver

    (venv) MacBookPro:HelloDjango zhangxm$ python manage.py runserver
    Watching for file changes with StatReloader
    Performing system checks...
    
    System check identified no issues (0 silenced).
    
    You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
    Run 'python manage.py migrate' to apply them.
    
    January 21, 2020 - 06:16:24
    Django version 2.2.9, using settings 'HelloDjango.settings'
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CONTROL-C.
    [21/Jan/2020 06:16:37] "GET / HTTP/1.1" 200 16348
    [21/Jan/2020 06:16:37] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
    [21/Jan/2020 06:16:37] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
    [21/Jan/2020 06:16:37] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
    [21/Jan/2020 06:16:37] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
    Not Found: /favicon.ico
    [21/Jan/2020 06:16:37] "GET /favicon.ico HTTP/1.1" 404 1977
    

    4、pycharm 打开Django工程

    打开目录为manage.py父目录文件夹, 然后配置虚拟环境解释器

    1)默认的解释器

    2)配置虚拟环境的解释器

    5、数据库迁移


    新建datasource并下载db drivers,Test Connection

    python manage.py migrate

    (venv) MacBookPro:HelloDjango zhangxm$ python manage.py migrate
    Operations to perform:
      Apply all migrations: admin, auth, contenttypes, 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 admin.0003_logentry_add_action_flag_choices... 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 auth.0009_alter_user_last_name_max_length... OK
      Applying auth.0010_alter_group_name_max_length... OK
      Applying auth.0011_update_proxy_permissions... OK
      Applying sessions.0001_initial... OK
    (venv) MacBookPro:HelloDjango zhangxm$ 
    
    

    这样重新启动python工程,就不会报数据库的错误。

  • 相关阅读:
    安卓项目文件夹解析
    网页嵌入腾讯视频方式
    Thinkphp3.23 连接MSSQL方法
    .NET 出现参数化查询 需要参数但未提供该参数的错误
    .NET 原理之 ViewState
    VS2012创建WebForm项目提示错误: 此模板尝试加载组件程序集 “NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”。
    及时返回,业务逻辑异步实现
    linux常用命令
    ES报错引发的问题
    mall项目遇到的异常
  • 原文地址:https://www.cnblogs.com/xidianzxm/p/12215213.html
Copyright © 2020-2023  润新知