Reputation: 246
I am in the middle of creating an encyclopedia project. On the home page is a list of entries and I want all the entries to be linked to their entry page.
Currently when I click on the link to an entry on the homepage, in this case the entry is called CSS, this is the error I get:
TypeError at /wiki/CSS/ entry() got an unexpected keyword argument 'entry' Request Method: GET Request URL: http://127.0.0.1:8000/wiki/CSS/
views.py
def css(request):
return render(request, "entries/css.html", {
"css_entry": util.get_entry("css")
})
def entry(request):
return render(request, entry, "encyclopedia/index.html", {
"entry": util.get_entry({"entry"})
})
urls.py
urlpatterns = [
path("", views.index, name="index"),
path("css/", views.css, name="css"),
path("<str:entry>/", views.entry, name="entry")
]
index.html
<ul>
{% for entry in entries %}
<li><a href = "{% url 'entry' entry %}">{{ entry }}</a></li>
{% endfor %}
</ul>
The frustrating thing is if I enter into the browser: http://127.0.0.1:8000/wiki/CSS/ it works and the page loads fine but not when I click the link from the homepage. Plus, if I remove the entry argument leaving it as {% url 'entry' %} then the homepage stops working and I get the following error:
NoReverseMatch at /wiki/ Reverse for 'CSS' not found. 'CSS' is not a valid view function or pattern name. Request Method: GET Request URL: http://127.0.0.1:8000/wiki/ Django Version: 3.1.1 Exception Type: NoReverseMatch
Upvotes: 0
Views: 2586
Reputation: 4095
As your entry
function take entry
. Do:
def entry(request, entry):
return render(request, entry, "encyclopedia/index.html", {
"entry": util.get_entry({"entry"})
})
Upvotes: 1