Django By Example - 学习笔记

Chapter 1 Building A Blog Application

1. Installing Django

Installing Python3 on Mac:

bash 复制代码
pip3 install python3

Creating Virtual Environment:

bash 复制代码
python3 -m venv .venv

Installing Django with pip3:

bash 复制代码
pip3 install django

Creating your first project:

bash 复制代码
django-admin startproject blog

Let's take a look at the generated project structure:

These files as follows:

  • manage.py

    A command-line utility to interact with your project. It is a thin wrapper around the django-admin.py tool.

  • blog/

    Your project directory consists of the following files:

    • init.py

      An empty file that tells Python to treat the blog directory as a Python module.

    • settings.py

      Settings and configuration for your project. Contains initial default settings.

    • urls.py

      The place where your URL patterns live. Each URL defines here is mapped to a view.

    • wigs.py

      Configuration to run your project as a WSGI application.

Note that:
The generated settings.py file includes a basic configuration to use a SQLite database and a list of Django applications that are added to your project by default. We need to create the tables in the database for the initial applications.

Click New Terminal and run the following commands:

python 复制代码
cd blog
python 复制代码
python3 manage.py migrate

The tables for the initial applications have been created in the database.

(未完待续)

相关推荐
SamChan9012 分钟前
对比 4 种主流 PDF 文档解析方案:PyMuPDF vs pdfplumber vs Apache PDFBox vs 大模型 OCR
python·ai·pdf·ocr·apache·机器翻译
cypking39 分钟前
Objective-C 语法完整学习手册(小白自学 + 开发备查)
c语言·开发语言·学习·objective-c
Terra.K8 小时前
Java异常学习[特殊字符]
java·开发语言·学习
安_8 小时前
如何构建和使用向量索引?HNSW 和 IVF 有什么区别?
python·ai
counting money9 小时前
Java IO流详解:从InputStream到文件操作实战
java·开发语言·python
坚持学习前端日记10 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
峥无10 小时前
从0到1手撕红黑树:封装实现 my_map 与 my_set(SGI-STL 源码级深度解析)
开发语言·c++·笔记·算法·stl
北斗落凡尘10 小时前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
不会代码的小猴10 小时前
3. 控件学习1
开发语言·c++·笔记·qt·算法
雪碧聊技术11 小时前
安装Python(保姆级教程)
python·版本更新·python下载