首页 > 解决方案 > 为什么我的 store.html 无法识别?

问题描述

我正在学习 Django Udemy 课程(James Carrigan),我只更新到 2.0.5

tree bookstore
bookstore
├── bookstore
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── settings.cpython-36.pyc
│   │   ├── urls.cpython-36.pyc
│   │   └── wsgi.cpython-36.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── db.sqlite3
├── manage.py
└── store
    ├── admin.py
    ├── apps.py
    ├── __init__.py
    ├── migrations
    │   ├── __init__.py
    │   └── __pycache__
    │       └── __init__.cpython-36.pyc
    ├── models.py
    ├── __pycache__
    │   ├── admin.cpython-36.pyc
    │   ├── __init__.cpython-36.pyc
    │   ├── models.cpython-36.pyc
    │   └── views.cpython-36.pyc
    ├── templates
    │   ├── store.html
    │   └── template.html
    ├── tests.py
    └── views.py

这些是我的看法

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

def store(request):
    return render(request,'store.html') 

网址

from django.contrib import admin
from django.urls import path
from django.conf.urls import url
from store import views

urlpatterns = [
    url(r'^', views.index ,name='index' ),
    url(r'^store', views.store ,name='store' ),
    path('admin/', admin.site.urls),
]

我在 HTML 样板文件中更改了行

<p>Welcome to mystery books and store template is changed!</p>

我去运行服务器时遇到问题 在此处输入图像描述

它没有看到 http://127.0.0.1:8000/storehttp://127.0.0.1:8000/index之间有任何区别

为什么我的其他 html 无法识别?

标签: django

解决方案


您不会结束您的正则表达式模式,因此第一个匹配所有内容。
确保你结束你的正则表达式$

url(r'^$', views.index ,name='index' ),
url(r'^store$', views.store ,name='store' ),

推荐阅读