1 Star 0 Fork 0

peterlzx1991/Django

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
README.txt 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
peterlzx1991 提交于 2020-04-12 17:16 . 2020 0412 1716
1. Create a django project:
Terminal: django-admin startproject pyshop .
# 'pyshop' is the name of the project
2. run web server
Terminal: python manage.py runserver
3. create an app named 'products'
Terminal + : python manage.py startapp products
4. view function
Open views.py, define the index(main page of products app) function, simply return the http response via class called ‘HttpResponse’
5. mapping the urls to the view function (so far, django don't know to call the view function when there is a '/product' request from the browser)
create a new python file called 'urls' under products file, mapping the url to the view function via path function
6. add the products app
open urls.py under pyshop file, it's the parent urls module.
7 create a model
Open models.py under products file
8 注册
open setting.py under pyshop file, add info into INSTALLED_APPS, info came from apps.py under products file.
9 makemigrations
Terminal: python manage.py makemigrations
Terminal: python manage.py migrate
10 admin panel
Terminal: python manage.py createsuperuser
open admin.py under products, 'admin.site.register(Product)'
11 显示产品给用户
open views.py 'from .models import Product'
add a new directory called 'templates' inside products file
add a new file called 'index.html' inside templates file
open views.py change the index function
open index.html
12 use base html, copy from 'https://getbootstrap.com/'
add a new file called 'base.html' inside the templates file.
do change under <body>
back to index.html '{% extends 'base.html'%}'
13 card 点替换图片
go https://getbootstrap.com/docs/4.4/components/card/, copy
back to index.html, do changes
14 加引导栏,美化
https://getbootstrap.com/docs/4.4/components/navbar/ copy
back to base.html do change under <body>
为了能让base.html复用
build a templates directory under PyShop file, 把base.html从 之前的文件夹,拖到新的templates里面,
open settings, TEMPLATES 'DIRS': [
os.path.join(BASE_DIR, 'templates')
]
美化:
open base.html
<body>
<nav class="navbar navbar-light bg-light">
<a class="navbar-brand" href="#">PyShop</a>
</nav>
<div class="container">
{% block content %}
{% endblock %}
</div>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/peterlzx1991/Django.git
[email protected]:peterlzx1991/Django.git
peterlzx1991
Django
Django
master

搜索帮助