Django 框架主要关注的是模型(Model)、模板(Template)和视图(Views),称为MTV模式。它们各自的职责如下:层次职责模型(Model),即数据存取层处理与数据相关的所有事务: 如何存取、如何验证有效性、包含哪些行为以及数据之间的关系等。模板(Template),即业务逻辑层处理与表现相关的决定: 如何在页面或其他类型文档中进行显示。视图(View),即表现层存取模型及...
创建APP在Django中的一个app代表一个功能模块。开发者可以将不同功能的模块放在不同的app中, 方便代码的复用。app就是项目的基石,因此开发博客的第一步就是创建新的app,用来实现跟文章相关的功能模块。打开命令行,进入项目所在的目录:(注意Django的操作必须在虚拟环境下进行)E:\>cd django_project
E:\django_project>进入虚拟环境...
教程的开发环境本教程的开发环境为:Win 10(64位)Python 3.7.0Django 2.2为了避免开发环境不同而导致的错误,建议读者使用相同的版本。注意:不少读者反馈 Django 2.1 版本在后面章节中会遇到 main.auth_user_old 的报错。这是版本兼容问题造成的。因此强烈建议读者使用其他小版本号,如 Django 2.2。安装Pythonpython的安装为比较...
1. 进入Python官网在浏览器地址栏中输入www.python.org并回车,或者点击这里,进入后页面如下如下:2. 下载Python安装包直接点击页面中的黄色“Download Python 3.12.4”按钮,或者选择导航栏中的“Download”,然后选择“Download for Windows”下的“Python 3.12.4”下载按钮,具体如下图:3. 选择自定义安装双击下载...
我是Django的坚定支持者,就像曾经我支持Flask一样。Flask的经历我在了解Python开发网站的第一站,就是Flask。Flask有着非常多的有点,比如代码非常优雅、框架非常简洁、插件非常丰富等等。但是,作为一个网站建设的小菜鸡,我并没有利用Flask搭建起一个完整的个人网站。究其原因,还是因为Flask过于灵活,所谓,都是路,反而不知道如何选择路。作为Flask的曾经使用者,我总...