[Fixed]-Django calling view method twice

1👍

From the log output, we can see that the second call to your view function is triggered by the URL /test/images/favicon.ico. You probably have a line like this in your template:

<link rel="shortcut icon" href="images/favicon.ico">

Note that there’s no slash before images, which means that the URL will be treated as relative to the current page URL, /test/. You should change this line to point to the correct location of your favicon (probably something like /static/img/favicon.ico), or delete it completely if you don’t have one.

The URL /test/images/favicon.ico is triggering your view function because
the pattern r'^test/' matches all URLs beginning with /test/. If you want it to only match the specific URL /test/, the line should be:

url(r'^test/$', views.test, name='test'),
👤gasman

Leave a comment