当尝试单击按钮重定向到 getonboard.html 时,出现以下错误:
django.urls.exceptions.NoReverseMatch: Reverse for 'getonboard' not found. 'getonboard' is not a valid view function or pattern name.
艺术数据库/urls.py:
path('getonboard/',views.getonboard,name='getonboard'),
模板/artdb/base.html:
<p><a class="btn btn-primary btn-lg" href="{% url 'getonboard' %}" role="button">Get onboard »</a></p>
艺术数据库/views.py:
def getonboard(request):
return render(request,'artdb/getonboard.html')
模板/artdb/getonboard.html:
{% extends "artdb/base.html" %}
{% block content %}
<h2>getonboard template</h2>
<p>this is the getonboard text</p>
{% endblock content %}
完整的主 urls.py:
"""winmalist URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('artdb/', include('artdb.urls')),
path('admin/', admin.site.urls),
]+static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
相关分类