Ask HN: How do you deal with the powerlessness feeling of coding?
&gt; For the last few months I&#x27;ve been learning back Django which was my first love. I&#x27;m learning back the django rest framework and today I have an issue where in the DRF interface the button for POST&#x2F;DELETE&#x2F;PUT&#x2F;PATCH don&#x27;t work. They don&#x27;t even send the POST&#x2F;DELETE&#x2F;PUT&#x2F;PATCH request, they just reload the page as if the only thing those button do where `window.location.reload();`.<p>It&#x27;s hard to know for sure without actually seeing it, but...<p>This sounds very much like a fairly typical JavaScript problem. Or to be more precise, a &quot;lack of JavaScript&quot; problem. Let me first explain what I think may be the problem and then <i>how you could look into solving it</i>.<p>The problem as described makes me think:<p>- There is a button which submits a form. It <i>should</i> use an XHR for the submission, which means there should be some JS event handler attached to the button.<p>- But instead of that, <i>if for whatever reason the handler was not attached correctly</i>, then the button would simply submit the form it belongs to in a default way, which would reload the page. This fits the description you give.<p>So, first thing, how can someone go about verifying if this is indeed the case of what is happening?<p>What you do is you open your browser development tools and look around for a couple of things. First, you load the page normally, and do not <i>yet</i> click the button. Now, you look in the console for any JS errors at all and, if there are any, see if one of them maybe either a. related in any way to the button, the form, the event handlers, etc, or b. there is one that <i>breaks JS execution</i>, which would prevent other code from being run. More: You inspect the button itself with the DOM inspector and verify if it actually has any click event handlers attached. Note that it may be the case that the handler is attached as a submit handler on the form, instead of as a click handler on the button. If there is <i>neither</i> of those, then it&#x27;s very likely that something has prevented some piece of JS from being run and the handlers from being attached.<p>After looking at that, still with your browser dev tools open, you set the network tab as visible, and then actually click the button and trace what happens. There&#x27;s a lot to learn about browser dev tools, and there is a lot of info out there, so when you have a chance, that&#x27;s something you could spend some time on. But right now you just want to check the request that happens when you click the button. In particular you need to look at the type of request and the &quot;initiator&quot;. These will tell you whether it is indeed a &quot;normal form submission&quot; or an &quot;XHR request&quot;.<p>Once you verify these things, if this is not the problem, then you&#x27;ll need to explore other options -which I cannot specify more due to the lack of information, of course-.<p>But if this is indeed the problem, that there&#x27;s no event handler attached and the form is simply submitted, then you need to investigate why there is no handler attached, obviously.<p>Again, try to search for any errors in the console, check id&#x27;s used on the form or button, check the template that generates the button and form. Also check the network template for any 4xx, 5xx, or any files that are not loading for whatever reason. It may be a misconfigured path, a missing library, a misconfigured MIME type... It can be a lot of things.<p>If you can&#x27;t find anything like this that gives you a clue, then it&#x27;s time to change the approach. Now start by looking for the origin of that button in the source. Where is it created? How is it created? Does it depend on any parameters? Are those correct? Does it depend on a <i>global</i> configuration? Is that correctly set up?<p>I can&#x27;t tell you anything more specific than this, but that is how you &quot;go about solving the problem&quot;. At some point, you&#x27;ll most likely find a misconfigured path, or a missing file or parameter. Or, at the very least, you&#x27;ll find an error message that can give you a clue of what is happening and what should be your next step. With that it will be much easier to ask questions.<p>----<p>So, in summary, you fight the powerlessness by actually trying to figure it out. There is no secret, really. There&#x27;s no magic thing people do to solve problems we haven&#x27;t seen before.<p>Note, also, that I cheated a bit. That is, going from your description I offered an experience I have previously had. But what if it was my first time? What if I had never seen this? The idea, then, is to first establish what is actually happening. You suggest &quot;...as if the only thing those button do where `window.location.reload();`&quot;. This is an hypothesis. So you verify it. You do the thing with the browser dev tools -which you learn to use beforehand, of course-, and try to verify if your hypothesis is correct.<p>There&#x27;s a small catch, though. Your hypothesis there is a bit &quot;too sophisticated&quot;. Why would someone attach some JS to do location.reload()? Could there be an easier explanation? That&#x27;s where the above comes into place: if you attache no handler at all, the submission is just a normal form submission; if the form has no explicit action declared, it will POST&#x2F;GET to the same current URL.<p>So, in a way, that <i>is</i> a small secret -but really, it&#x27;s not secret- thing: always start verifying from the <i>simplest</i> things. Always check the most simple hypothesis. This can even be extensible to &quot;always check the most visible&#x2F;obvious things&quot;, like always checking the error console and always giving the network tab in the dev tools a look for 4xxs or 5xxs.<p>Also, as already mentioned: owning the code. But this does not necessarily mean making the calls. Sure, you did not make the decision to use DRF, ok. But you can still make the effort to learn DRF to a desirable extent.