Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the tags and your template code, I gather that you are using Django. To understand your issue, you'll have to understand how Django views work relative to your browser, and what happens when your browser issues a request for a given url.</p> <h2>What happens on the <code>Django</code> side:</h2> <p>What happens when you request an url is that your base <code>urls.py</code> file will be searched for pattern matching your url. If a pattern is encountered, then the corresponding <code>view</code> will be called.<br> The <code>view</code>will carry out its logic, and will use a <code>template</code> to render its response into <code>html</code>.</p> <h2>What happens from your browser's point of view</h2> <p>The browser requested an url, and received a response, it is not aware of the fact that a view was called, and that it fetched a template somewhere. </p> <h2>What this means to you</h2> <p>The fact that your <code>search.js</code> file is located next to your template is <strong>totally irrelevant</strong>, as your browser <strong>never requested any file from this directory</strong>, it's the <code>view</code> that did, when it fetched its <code>template</code>.</p> <p>Actually, your browser's request for <code>search.js</code> will be forwarded to <code>Django</code> by your webserver and will (most likely) result in a <code>404</code> error, unless <code>search.js</code> resolves to a view in your <code>urls.py</code>.</p> <h2>How you can use this to solve your issue</h2> <p>You'll need to serve your <code>search.js</code> file from a directory that can be accessed by the browser. Usually, this is done in three steps:</p> <ol> <li><p>Configure your webserver so that it serves any path starting with <code>/static/</code> on its own (somehow, this means not forwarding the request to <code>Django</code>).<br> In Apache, you'd use the following rule: <code>Alias /static/ /YOUR/STATIC/DIRECTORY/</code></p></li> <li><p>Configure <code>Django</code>'s <code>settings.py</code> to use <code>/YOUR/STATIC/DIR</code> as <code>STATIC_ROOT</code>, and <code>/static/</code> as <code>STATIC_URL</code>.</p></li> <li><p>Put your <code>search.js</code> file in your <code>/YOUR/STATIC/DIR/</code></p></li> <li><p>Use <code>src="/static/search.js</code> to reference your file in your <code>html</code> template.</p></li> </ol> <p>One last thing: if you're using the development server, you might need to ensure your <code>STATIC_URL</code> starts with the full path to your server, including the port. (Or you might have issues with browser security policies).</p> <h2>A few additions:</h2> <p>Your should be using template tags so that you don't have to write <code>/static/</code> in your template.<br> You should be using <code>manage.py collectstatic</code> to autimatically put static files in your static directory.</p> <p>Most importantly, <strong>you should investigate what Django's MVC (or MTV) model is about</strong>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload