每天写1000字简友广场

Django环境配置

2019-08-19  本文已影响0人  b8a7c7695f14

django

Django是一个开放源代码的Web应用框架,由Python写成。采用了MTV的框架模式,即模型M,视图V和模版T。它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内容为主的网站的,即是CMS(内容管理系统)软件。并于2005年7月在BSD许可证下发布。这套框架是以比利时的吉普赛爵士吉他手Django Reinhardt来命名的

项目开发环境

创建项目

通过命令行的方式:首先要进入到安装了django的虚拟环境中。然后执行命令:
django-admin startproject [项目的名称]

django-admin startproject mybook

通过此命令创建django项目,下图可以看见相关的路径

image

<figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption>

项目结构分析:

创建app

所有和某个模块相关的视图都写在对应的app的views.py中,并且模型和其他的也是类似。然后django已经提供了一个比较方便创建app的命令叫做python manage.py startapp [app的名称]。把所有的代码写在各自的app中。

image

<figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption>

因为这个项目是不大,个人认为不用创建app文件夹

运行项目

直接在命令行python3 manage.py runserver 0.0.0.0:8000

image

<figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption>

pycharm启动项目

image

<figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption>

image

<figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption>

image

<figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption>

image

<figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption>

我们可以看见小飞机升起来了

其他配置

image

<figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption>

这里的数据库是mysql

直接在settings.py文件中添加数据库配置信息,这里不会新建数据库,所以你需要在mysql自己新建数据库

image

<figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption>

别忘了在init.py引用pymql

image

<figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption>

再次运行起来,没有报错了配置完成

上一篇 下一篇

猜你喜欢

热点阅读