如何从以下index.html调用about.html?向urls和视图添加什么?包括about和index在内的所有html文件都收集在project/static文件夹中。
# This is part of the index.html, where I want to call the about.html
<div class="card-footer">
<a href="#" class="btn btn-primary">Learn More</a>
</div>
# Here is the project/urls.py
from django.contrib import admin
from django.urls import path
from app1 import views
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index),
]
urlpatterns += staticfiles_urlpatterns()发布于 2019-07-04 03:54:01
如果您在一个html文件中,并且想要打开另一个html文件,您可以在html文件中放入如下内容:
<a href="{% url 'about' %}"> Go to About </a>这将在单词Go to About上创建一个可点击的链接。然后,您可以将其放置在页面上的任意位置。在urlpattern中,您需要创建一个新路径,如下所示
path('about', view.AboutView.as_view(), name='about')在您的views.py中,您必须使用templateView创建一个名为AboutView的类,并将您的html文件的名称设置为template_name,如下所示:
from django.views.generic.base import *
class AboutView(TemplateView):
template_name = "about.html"如果你需要更多的帮助来理解这段代码,或者想做一些其他的事情,请告诉我
发布于 2019-07-04 14:25:54
在urls.py中添加关于url
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index),
path('about/', views.about, name="about"),
]在views.py文件中添加关于视图
def about(request):
# render your template here在index.html中
<div class="card-footer">
<a href="{% url 'about' %}" class="btn btn-primary">Learn More</a>
</div>https://stackoverflow.com/questions/56876949
复制相似问题