I
I
Ivan Privedenets2019-04-02 19:46:42
Django
Ivan Privedenets, 2019-04-02 19:46:42

How can I make the search image appear on all pages?

Hey! An image appears behind the search button in the form.

<form id="search" action="{% url 'Home_page_url' %}" method="
                        {% csrf_token %}
                        <input id="head-form" type="search" placeholder="Поиск..." maxlength="50" 
                         name="search">  
                        <input type="image" src="static/img/search2.png">
                </form>

This code is placed in base.html and, as it should be, this template is the main one and various blocks are inserted into it, for example, "content block". The bottom line is that when I'm on the first page of the site, where url = 127.0.0.1:8000 everything works fine, but when the path changes, for example 127.0.0.1:8000/page1/, the image is not displayed on the page.
What the terminal says when it didn't find
Not Found: /page1/static/img/search2.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2019-04-02
@Ivan-Proger

Before taking on Django, it's worth learning the basics. Specifically, what are relative and absolute URLs. Well, the Django documentation on maintaining statics is also worth reading so as not to hardcode paths.

<input type="image" src="{% static 'img/search2.png' %}">

A
Arseny, 2019-04-02
Matytsyn @ArsenyMatytsyn

To be sure to catch static, you need to run the collectstatic command. It will collect all the dependencies of the project into a statics folder and hardcoded paths will work from there.
As for the rest, I agree with the authors of the previous speakers, you need to read the documentation. In the project deployment example, all this is painted at the “copy and work” level.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question