1 Star 0 Fork 0

peterlzx1991/Django

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
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>

空文件

简介

暂无描述 展开 收起
Python
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/peterlzx1991/Django.git
[email protected]:peterlzx1991/Django.git
peterlzx1991
Django
Django
master

搜索帮助