找不到"hobbieswithCSS.html"的反向按钮.'hobbieswithCSS.html'不是有效的视图函数或模式名称(已解决) [英] Reverse for 'hobbieswithCSS.html' not found. 'hobbieswithCSS.html' is not a valid view function or pattern name (solved)

查看:51
本文介绍了找不到"hobbieswithCSS.html"的反向按钮.'hobbieswithCSS.html'不是有效的视图函数或模式名称(已解决)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Django时,我尝试将hobbieswithCSS.html文件附加到我的网站.我是Django的初学者,所以我很自然地遇到了这样的问题(标题中).

I am trying to attach hobbieswithCSS.html file to my website, while using Django. I am a beginner when it comes to Django, so I have naturally came across some problems (in the title) like this.

我的主页上有这个锚标签-

I have this anchor tag on my homepage -

<a href="{% url 'basic_app:hobbieswithCSS.html' %}">My Hobbies</a>

我的views.py文件中有此视图-

I have this view in my views.py file -

def hobbieswithCSS(request):
    return render(request,'basic_app/hobbieswithCSS.html')

我认为,主要问题将与urls.py文件中的urlpatterns有关,因为我不确定如何设置它.这些是我的urlpatterns-

I think, that the main problem will be with the urlpatterns in urls.py file, because I am not sure how to set it up. These are my urlpatterns -

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^admin/', admin.site.urls),
    url(r'^basic_app/',include('basic_app.urls')),
    url(r'^logout/$',views.user_logout,name='logout'),
    url(r'^$', views.hobbieswithCSS, name='hobbieswithCSS'),
]

有人可以告诉我,当我尝试在服务器上运行它时,如何更改代码以显示hobbieswithCSS.html文件?

Could anybody please tell me, how could I change the code in order to make that hobbieswithCSS.html file display, when I am trying to run it on my server?

非常感谢您的帮助.

该问题最初是该问题的前传-位于/hobbies/的TemplateDoesNotExist(已解决)

This question was originally a prequel of this question - TemplateDoesNotExist at /hobbies/ (solved)

推荐答案

必须为:

<a href="{% url 'hobbieswithCSS' %}">My Hobbies</a>

没有 basic_app .

另外,索引和爱好的路径相同.您必须更改您的网址路径:

Also you have the same path for index and hobbies . You have to change your url path:

urlpatterns = [
    url(r'^$', views.index, name='index'),
    ...
    url(r'^hobbies/$', views.hobbieswithCSS, name='hobbieswithCSS'),
]

这篇关于找不到"hobbieswithCSS.html"的反向按钮.'hobbieswithCSS.html'不是有效的视图函数或模式名称(已解决)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆