• django 学习 (一) 简单试用


    主要记录关于环境搭建的问题

    安装django

    推荐使用venv,virtualenv 也是一个不错的选择

    python  -m venv venv
    source   venv/bin/activate
    python -m pip install Django

    创建一个简单的project

    使用django-admin

    django-admin startproject demoapp 

    效果

    运行

    python manage.py runserver

    包含admin 运行

    先执行db 创建

    python manage.py  migrate

    账户创建

    python manage.py  createsuperuser

    重启服务登陆效果



    docker 运行

    • requirements.txt
     
    Django==3.1.4
    • Dockerfile
    FROM python:3.8.7-slim
    WORKDIR /app
    COPY . /app
    RUN pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt
    EXPOSE 8000
    CMD [ "python","manage.py","runserver","0:8000" ]

    参考命令

    • django-admin
    Type 'django-admin help <subcommand>' for help on a specific subcommand.
    Available subcommands:
    [django]
        check
        compilemessages
        createcachetable
        dbshell
        diffsettings
        dumpdata
        flush
        inspectdb
        loaddata
        makemessages
        makemigrations
        migrate
        runserver
        sendtestemail
        shell
        showmigrations
        sqlflush
        sqlmigrate
        sqlsequencereset
        squashmigrations
        startapp
        startproject
        test
        testserver
    Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).
     
     
    • manage.py
    Type 'manage.py help <subcommand>' for help on a specific subcommand.
    Available subcommands:
    [auth]
        changepassword
        createsuperuser
    [contenttypes]
        remove_stale_contenttypes
    [django]
        check
        compilemessages
        createcachetable
        dbshell
        diffsettings
        dumpdata
        flush
        inspectdb
        loaddata
        makemessages
        makemigrations
        migrate
        sendtestemail
        shell
        showmigrations
        sqlflush
        sqlmigrate
        sqlsequencereset
        squashmigrations
        startapp
        startproject
        test
        testserver
    [sessions]
        clearsessions
    [staticfiles]
        collectstatic
        findstatic
        runserver

    说明

    django 脚手架工具提供的命令还是比较多的,可以都试试,加深了解

    参考资料

    https://docs.djangoproject.com/en/3.1/intro/tutorial01/

  • 相关阅读:
    一个小案例精通lamda表达式
    你想被开除吗?来看看程序员【离职小技巧】吧
    让 Flutter 在鸿蒙系统上跑起来
    “TensorFlow 开发者出道计划”全攻略,玩转社区看这里!
    环形单链表的增删改查、约瑟夫环两种解法
    一万字详解 Redis Cluster Gossip 协议
    Lambda表达式
    Linux系统中如何进入退出vim编辑器,方法及区别
    成为博客主的第一天
    【秋招内推】近期互联网公司秋招内推合集
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14213249.html
Copyright © 2020-2023  润新知