# Django **Repository Path**: peterlzx1991/Django ## Basic Information - **Project Name**: Django - **Description**: No description available - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-04-12 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## 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
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 为了能让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