微服务网关接口规范
310
2022-08-31
Django(part2)--创建项目与Django目录结构(django优秀开源项目目录)
学习笔记,仅供参考
文章目录
Django框架开发
创建项目的指令Django目录结构
Django框架开发
创建项目的指令
创建项目的指令:
django-admin startproject 项目名称#比如django-admin startproject mywebsite1
举个例子
我们先进入一个指定的文件夹,再输出如下命令:
F:\MyStudio\PythonStudio\goatbishop.project01\Django>django-admin startproject mywebsite1
查看该文件夹下的文件:
F:\MyStudio\PythonStudio\goatbishop.project01\Django>dir /o 驱动器 F 中的卷是 山羊卷 卷的序列号是 3C68-9CA1 F:\MyStudio\PythonStudio\goatbishop.project01\Django 的目录2020/06/13 11:15
可以看到我们多了一个mywebsite1文件夹,进入mywebsite1文件夹,查看文件夹下内容:
F:\MyStudio\PythonStudio\goatbishop.project01\Django>cd ./mywebsite1F:\MyStudio\PythonStudio\goatbishop.project01\Django\mywebsite1>dir 驱动器 F 中的卷是 山羊卷 卷的序列号是 3C68-9CA1 F:\MyStudio\PythonStudio\goatbishop.project01\Django\mywebsite1 的目录2020/06/13 11:15
我们看到mywebsite1文件夹下还有一个mywebsite1文件夹,并且多了一个manage.py
现在,我们执行下面的命令:
F:\MyStudio\PythonStudio\goatbishop.project01\Django\mywebsite1>python manage.py runserverTraceback (most recent call last): File "manage.py", line 10, in main from django.core.management import execute_from_command_lineModuleNotFoundError: No module named 'django'The above exception was the direct cause of the following exception:Traceback (most recent call last): File "manage.py", line 21, in
报错了!
按照提示信息,我们现在配置一下环境变量,将下面两条路径加到环境变量中去:
#diango的路径F:\software\Anaconda\Lib\site-packages\django;#python的scripts路径F:\software\Anaconda\Scripts;
配置完成后,我们再次运行下面的代码:
F:\MyStudio\PythonStudio\goatbishop.project01\Django\mywebsite1>python manage.py runserverWatching for file changes with StatReloaderPerforming 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.June 13, 2020 - 12:48:32Django version 2.2.13, using settings 'mywebsite1.settings'Starting development server at the server with CTRL-BREAK.
在结果中,我们看到下面这行字:
Starting development server at manage.py runserver 5000Watching for file changes with StatReloaderPerforming 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.June 13, 2020 - 13:39:57Django version 2.2.13, using settings 'mywebsite1.settings'Starting development server at the server with CTRL-BREAK.
现在,我们在浏览器中打开manage.py runserver 启动服务python manage.py startapp 创建应用python manage.py migrate 数据库迁移
mywebsite1项目包文件夹
项目包的主文件夹(默认与项目名称一致)__init__.py
项目初始化文件,服务器启动时自动运行
wsgi.py
WEB服务网关接口的配置文件,仅部署项目时使用
urls.py
项目的基础路由配置文件,所有的动态路径必须先走该文件进行匹配
settings.py
Django的配置文件,此配置文件中的一些全局变量将为Django框架的运行传递参数启动服务时,会自动调用该文件此配置文件中也可以定义一些自定义的变量用于作用全局作用域的数据传递
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~