这是我的url.py
代码:
urlpatterns = [
url(r'^test/', views.test, name='test'),
]
这是我的views.py
代码:
def test(request):
print ("++++++++++++++++++++++++++++++++++++++++++++++++")
return render(request, 'my_app/index_test.html')
这是我从控制台输出的
Django version 1.10.6, using settings 'some_project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
++++++++++++++++++++++++++++++++++++++++++++++++++++++
[03/Apr/2017 01:24:41] "GET /test/ HTTP/1.1" 200 26814
[03/Apr/2017 01:24:41] "GET /static/css/normalize.css HTTP/1.1" 200 8053
[03/Apr/2017 01:24:41] "GET /static/css/bootstrap.min.css HTTP/1.1" 200 102897
[03/Apr/2017 01:24:41] "GET /static/css/font-awesome.min.css HTTP/1.1" 200 21979
[03/Apr/2017 01:24:41] "GET /static/css/animate.css HTTP/1.1" 200 63414
[03/Apr/2017 01:24:41] "GET /static/css/gg_preloading.css HTTP/1.1" 200 3816
[03/Apr/2017 01:24:41] "GET /static/css/prettyPhoto.css HTTP/1.1" 200 19888
[03/Apr/2017 01:24:41] "GET /static/css/style.css HTTP/1.1" 200 23649
[03/Apr/2017 01:24:41] "GET /static/js/jquery-1.10.2.min.js HTTP/1.1" 200 93107
[03/Apr/2017 01:24:41] "GET /static/js/bootstrap.js HTTP/1.1" 200 58327
[03/Apr/2017 01:24:41] "GET /static/js/waypoints.min.js HTTP/1.1" 200 8044
[03/Apr/2017 01:24:41] "GET /static/js/jquery.scrollto.min.js HTTP/1.1" 200 2434
[03/Apr/2017 01:24:41] "GET /static/js/jquery.localscroll.min.js HTTP/1.1" 200 1560
[03/Apr/2017 01:24:41] "GET /static/js/scripts.js HTTP/1.1" 200 5183
[03/Apr/2017 01:24:41] "GET /static/js/less.min.js HTTP/1.1" 200 143621
[03/Apr/2017 01:24:41] "GET /static/img/empty_1.png HTTP/1.1" 200 15358
[03/Apr/2017 01:24:41] "GET /static/img/empty_2.png HTTP/1.1" 200 15411
[03/Apr/2017 01:24:41] "GET /static/pic/%D0%9D%D0%91_Banner-6.jpg HTTP/1.1" 200 47285
[03/Apr/2017 01:24:41] "GET /static/pic/hotlog_counter.png HTTP/1.1" 200 1700
[03/Apr/2017 01:24:41] "GET /static/pic/%D0%9D%D0%91_Banner-5.jpg HTTP/1.1" 200 31588
[03/Apr/2017 01:24:41] "GET /static/pic/%D0%9D%D0%91_Banner-1.jpg HTTP/1.1" 200 33355
[03/Apr/2017 01:24:41] "GET /static/pic/%D0%9D%D0%91_Banner-2.jpg HTTP/1.1" 200 29322
[03/Apr/2017 01:24:41] "GET /static/pic/%D0%9D%D0%91_Banner-3.jpg HTTP/1.1" 200 24960
[03/Apr/2017 01:24:41] "GET /static/pic/%D0%9D%D0%91_Banner-4.jpg HTTP/1.1" 200 23886
[03/Apr/2017 01:24:42] "GET /static/less/style.less HTTP/1.1" 200 4607
[03/Apr/2017 01:24:42] "GET /static/pic/%D0%9D%D0%91_%D0%98%D1%81%D1%85%D0%BE%D0%B4%D0%BD%D0%B8%D0%BA-5.jpg HTTP/1.1" 200 129141
[03/Apr/2017 01:24:42] "GET /static/pic/%D0%9D%D0%91_%D0%98%D1%81%D1%85%D0%BE%D0%B4%D0%BD%D0%B8%D0%BA-6.jpg HTTP/1.1" 200 95125
[03/Apr/2017 01:24:42] "GET /static/pic/%D0%9D%D0%91_%D0%98%D1%81%D1%85%D0%BE%D0%B4%D0%BD%D0%B8%D0%BA-7.jpg HTTP/1.1" 200 101621
[03/Apr/2017 01:24:42] "GET /static/pic/%D0%9D%D0%91_%D0%98%D1%81%D1%85%D0%BE%D0%B4%D0%BD%D0%B8%D0%BA-4.jpg HTTP/1.1" 200 110054
[03/Apr/2017 01:24:43] "GET /static/img/fairy_logo_large.png HTTP/1.1" 200 5794
[03/Apr/2017 01:24:43] "GET /static/font/fontawesome-webfont.woff?v=4.2.0 HTTP/1.1" 200 65452
[03/Apr/2017 01:24:43] "GET /static/img/fairy_bckgrnd.jpg HTTP/1.1" 200 226213
[03/Apr/2017 01:24:43] "GET /static/img/sprite_social_element.png HTTP/1.1" 200 11187
[03/Apr/2017 01:24:43] "GET /static/img/lang_picto.png HTTP/1.1" 200 6577
[03/Apr/2017 01:24:43] "GET /static/img/bullet.png HTTP/1.1" 200 2828
++++++++++++++++++++++++++++++++++++++++++++++++++++++
[03/Apr/2017 01:24:43] "GET /test/images/favicon.ico HTTP/1.1" 200 26814
[03/Apr/2017 01:24:43] "GET /static/img/fairies_features.png HTTP/1.1" 200 482983
[03/Apr/2017 01:24:43] "GET /static/img/best.png HTTP/1.1" 200 72272
[03/Apr/2017 01:24:43] "GET /static/pic/%D0%9D%D0%91_%D0%98%D1%81%D1%85%D0%BE%D0%B4%D0%BD%D0%B8%D0%BA-11.jpg HTTP/1.1" 200 262491
[03/Apr/2017 01:24:43] "GET /static/pic/%D0%9D%D0%91_%D0%98%D1%81%D1%85%D0%BE%D0%B4%D0%BD%D0%B8%D0%BA-8.jpg HTTP/1.1" 200 255375
[03/Apr/2017 01:24:43] "GET /static/img/video.png HTTP/1.1" 200 2672
[03/Apr/2017 01:24:43] "GET /static/pic/%D0%9D%D0%91_%D0%98%D1%81%D1%85%D0%BE%D0%B4%D0%BD%D0%B8%D0%BA-9.jpg HTTP/1.1" 200 329229
[03/Apr/2017 01:24:43] "GET /static/pic/%D0%9D%D0%91_%D0%98%D1%81%D1%85%D0%BE%D0%B4%D0%BD%D0%B8%D0%BA-10.jpg HTTP/1.1" 200 160719
我重新加载页面后或只是去了它,
你可以看到它打印++++++++++++++++++++++++++++++++++
两次。
我该怎么办?
答案 0 :(得分:0)
从日志输出中,我们可以看到第二次调用您的视图函数是由URL /test/images/favicon.ico
触发的。你的模板中可能有这样的一行:
<link rel="shortcut icon" href="images/favicon.ico">
请注意,images
之前没有斜杠,这意味着该网址将被视为相对于当前网页网址/test/
。您应该更改此行以指向您的favicon的正确位置(可能类似于/static/img/favicon.ico
),或者如果您没有,则将其完全删除。
网址/test/images/favicon.ico
正在触发您的查看功能,因为
模式r'^test/'
匹配以/test/
开头的所有网址。如果您希望仅匹配特定网址/test/
,则该行应为:
url(r'^test/$', views.test, name='test'),