-1

This seems like I must be missing something really simple. I'm trying to use the url command for a link. I keep getting a NoReverseMatch error. The code in the HTML looks like this:

a href="MyApp/Batch_Up_Load">Batch Upload</a

a href="{% url 'MyApp/Batch_Up_Load' %}">test</a

I'm just learning this so I duplicated the link, one in a button and one as an url. If I take out the second line the HTML loads find and the button takes me to the correct page. When I add the second line I get the NoReverseMatch error. I have it added to the installed apps in the settings page but I would think if I had done this wrong the first button wouldn't work at all.

If instead I link it to a name in the base module like this: test

it works fine. Is there some place special I need to list the MyApp application in order for python to find it when using url?


  • `url` tag contains `name` not actual route. – Sunderam Dubey Apr 16 '22 at 16:02
  • Have you registered your app in `INSTALLED_APPS` in `settings.py`? – Sunderam Dubey Apr 16 '22 at 18:26
  • Have you defined `templates` in `"DIRS":[BASE_DIR / "templates"]` in `TEMPLATES` in `settings.py`, but only if you are using outside templates folder where all app's templates exist. Finally, at last this post can be helpful for you , https://stackoverflow.com/questions/38390177/what-is-a-noreversematch-error-and-how-do-i-fix-it – Sunderam Dubey Apr 16 '22 at 18:34
  • Thank you for all your help. You've given me some good things to look at and I'll review the tour and how to ask links. I've added the templates directory and the app in the settings, still having the same problem but I understand it more and think I'll be able to figure it out. But if you have any other thoughts I'm open. Thanks again for your time. – NurseStacey Apr 16 '22 at 18:50
  • Can you edit the question with your current full `settings.py`?, and remove this error traceback. – Sunderam Dubey Apr 17 '22 at 09:02

1 Answers1

0

Url tag works with name in path.

For example:

urls.py

path('MyApp/Batch_Up_Load/',views.batch_upload,name='batch_upload')

In your template file

<a href="{% url 'batch_upload' %}"> batches </a>

So, it will render the desired page, url tag is used with name of path().

In your case:

<a href="MyApp/Batch_Up_Load/">Batch Upload</a>

It will render.

a href="{% url 'MyApp/Batch_Up_Load' %}">test</a

It will not render as url takes name.

Note:: Its recommended, if you give / at the end of your every route or path.

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
  • 1
    Thank you for your reply. I have the line path('Batch_Up_Load', views.Batch_Up_Load, name='Batch_Up_Load'), in my url and I tried writing it the way you said, batches and I still get the same error. I've tried adding '/' to various spots but the documentation makes me think that should be necessary. I feel like I must be missing something in settings to let it know where to redirect to. – NurseStacey Apr 16 '22 at 17:07
  • Is that what you want, when we have to use `url` or when we give actual `route`, and please edit your question and correct anchor tag, place `<` and `>`. – Sunderam Dubey Apr 16 '22 at 17:08
  • @NurseStacey can you update the full traceback of your code? – Sunderam Dubey Apr 16 '22 at 17:13
  • 1
    Thanks for all the help everyone. I finally figured out that I was missing the namespace of the app in the URL statement (it should have been % url 'MyApp:Batch_Up_Load' %) and once I figured it out it didn't occur to me that it was case sensitive. This last bit is a bit of foolishness on my part. – NurseStacey Apr 18 '22 at 13:53