django's Introduction
[图灵图书].Django基础教程 使用django1.11.29版本 创建 Django 项目 执行 python django-admin.py startproject <name> 命令,其中 <name> 是想创建的项目名 称。 创建 Django 应用 1 执行 python manage.py startapp <appname> 命令,其中 <appname> 是想创建的应用名称。 2 把应用名称添加到项目配置目录中的 settings.py 文件里,放到 INSTALLED_APPS 列表的末 尾,告诉 Django 项目这个应用的存在。 3 在项目的 urls.py 文件中添加一个映射,指向新建的应用。 4 在应用的目录中新建 urls.py 文件,把入站 URL 与视图对应起来。 5 在应用的 view.py 文件中编写所需的视图,确保视图返回一个 HttpResponse 对象。 添加模型 添加模型的过程可以分为以下 5 步。 首先在 Django 应用的 models.py 文件中定义模型。 更新 admin.py,注册新增的模型。 生成迁移:python manage.py makemigrations <app_name>。 运行迁移:python manage.py migrate。在数据库中创建模型所需的表和字段。 创建或编辑填充脚本。 有时你可能想删除数据库,重头再来。具体步骤如下。注意,本书使用的是 SQLite 数据库,此外 Django 还支持其他数据库引擎。 如果 Django 开发服务器正在运行,停止。 如果使用的是 SQLite 数据库,删除 Django 项目根目录中的 db.sqlite3 文件。这个文件与 manage.py 脚本位于同一级目录中。 如果修改过应用的模型,执行 python manage.py makemigrations <app_name> 命令,记得把 <app_name> 替换成 Django 应用的名称(例如 rango。)如果未修改模型,跳过这一步。 执行 python manage.py migrate 命令,新建数据库文件(使用 SQLite 的话),并创建数据 库表。 执行 python manage.py createsuperuser 命令,创建一个超级用户。 最后,运行填充脚本,在新数据库中插入可信的测试数据。
django's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.