Django_02.Start An App(创建第一个应用)

python manage.py startapp blog
(在 installed_apps 增加 'blog')

在 blog/views.py 中写入:

# blog/views.py
from django.shortcuts import render

def index(request):
    return render(request, 'blog/index.html')

template/blog/index.html

{% extends 'home/base.html' %}

{% block title %}
    Blog_Home
{% endblock %}

{% block content %}
    

Blog home!

{% endblock %}

blog/urls.py

from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='blog-home'),
]

主 url 中增加路由:

from django.urls import path, include
...
path('blog/', include('blog.urls')

你可能感兴趣的:(Django_02.Start An App(创建第一个应用))