Django 02 shopping mall project (start configuring, building databases, testing route, establishing a base class html)

1、setting

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
New static resource folder and will use some of the folder, and register
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

2, the drive installation mysql

Here Insert Picture Description

3, building a database

Login
Here Insert Picture Description
New Database

Here Insert Picture Description
New Finish to exit
Here Insert Picture Description
python manage.py migrate
Here Insert Picture Description

注意:在执行这一步的时候出现问题参考下面两个网址
https://blog.csdn.net/weixin_42186490/article/details/90416981
https://blog.csdn.net/weixin_30278237/article/details/95475446

4, connect to the database

Here Insert Picture Description
Here Insert Picture Description

这一步如果出现问题参考下面网址
https://www.cnblogs.com/zzliu/p/10806854.html
https://www.cnblogs.com/jcxioo/p/11606044.html

5. Create a test route

Create a route file:
Here Insert Picture Description
Creating index route:

from App import views
from django.urls import path

app_name='axf01'
urlpatterns = [
    path('index/', views.index,name='index'),
]

Here Insert Picture Description

Create a view function:

from django.http import HttpResponse
from django.shortcuts import render

def index(request):
    return HttpResponse('index')

Here Insert Picture Description
Connection routing:

# 注意django1和django2 include这里略有不同,否则下一步运行的时候会报错
# 注意一下自己的django版本,我这里是django2
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('axf/', include(('App.urls','axf01'),namespace='axf01')),
]

Here Insert Picture Description

6, run

python manage.py runserver
Here Insert Picture Description
access
Here Insert Picture Description

7, the base class construction html

templates/base.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{ title }}</title>

    {% block ext_css %}
    {% endblock %}

</head>
<body>
    {% block header %}
    {% endblock %}

    {% block content%}
    {% endblock %}

    {% block footer %}
    {% endblock %}

    {% block ext_js %}
    {% endblock %}
</body>
</html>

templates/base_main.html

{% extends 'base.html' %}

{% block ext_css %}
{% endblock %}

Here Insert Picture Description

Published 87 original articles · won praise 20 · views 1638

Guess you like

Origin blog.csdn.net/a__int__/article/details/103434835