代码之家  ›  专栏  ›  技术社区  ›  Richard Rublev

为什么无法识别my store.html?

  •  0
  • Richard Rublev  · 技术社区  · 7 年前

    我正在学习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>
    

    我在运行服务器时遇到问题 enter image description here

    我们看不出 http://127.0.0.1:8000/store http://127.0.0.1:8000/index

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

    1 回复  |  直到 7 年前
        1
  •  2
  •   Lemayzeur    7 年前

    你没有结束你的正则表达式模式,所以第一个匹配所有的东西。
    确保以 $

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