29π
In your index.html
you gave poll_id
as an argument, but thatβs just the name the argument will have within the detail
function; it is not defined in your template. The actual value you want to call the function with is probably poll.id
.
13π
My mistake was a typo on detail.html
:
<form action={% url 'polls:vote' polls.id %}" method="post">
should have been
<form action={% url 'polls:vote' poll.id %}" method="post">
It took a while for me to realise the django traceback page was pointing me to the relevant line of code the whole time. :$
- [Django]-CORS error while consuming calling REST API with React
- [Django]-Django Generic Views using decorator login_required
- [Django]-Filtering using viewsets in django rest framework
1π
This happened to me when I was reading tutorial. I didnβt change poll_id to pk:
url(r'^(?P<poll_id>\d+)/$', views.DetailView.as_view(), name='detail'),
vs
url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'),
- [Django]-How do I install psycopg2 for Python 3.x?
- [Django]-Django β getting Error "Reverse for 'detail' with no arguments not found. 1 pattern(s) tried:" when using {% url "music:fav" %}
- [Django]-How can I chain Django's "in" and "iexact" queryset field lookups?
1π
I encountered this error when I was using a string as a raw value, rather than surrounding by quotes i.e.
{% url 'my_view' string_val %}
instead of
{% url 'my_view' 'string_val' %}
- [Django]-Django composite unique on multiple model fields
- [Django]-How to get getting base_url in django template
- [Django]-Passing STATIC_URL to file javascript with django
0π
I struggled with this for a while. Then I noticed I had put poll.id and not Poll.id with a (capital P)
- [Django]-Django :How to integrate Django Rest framework in an existing application?
- [Django]-Filtering dropdown values in django admin
- [Django]-Negating a boolean in Django template
0π
also, in
polls/urls.py
i had spelling error
url(rβ^(?P[0-9]+)/$β, views.detail, name=βdetailsβ),
vs the correct code
url(rβ^(?P[0-9]+)/$β, views.detail, name=βdetailβ),
spent some time looking for the error, so look for proper spelling. lol
- [Django]-Django-Forms with json fields
- [Django]-Django connection to postgres by docker-compose
- [Django]-Using django-admin on windows powershell
0π
The error got sorted out for me after correcting the filter condition in views.py.
snippet of my views.py
def post_share(request, post_id):
post = get_object_or_404(Post, id=post_id, status='Published')
snippet from my models.py
class Post(models.Model):
STATUS_CHOICES=(
('draft','Draft'),
('published','Published'),
)
1st value is stored in the database and the second value is for displaying to the users.
raw data from my mysql DB
+---------------------------------------+-----------+
| title | status |
+---------------------------------------+-----------+
| Revolution 2020 | published |
| harry potter and the sorcerer's stone | published |
| harry potter and the cursed child | draft |
| five point someone | published |
| half girlfriend | draft |
| one night at the call center | published |
| Django by example | published |
+---------------------------------------+-----------+
When I had used βpublishedβ, I was getting the said error. Once I changed the filter to βPublishedβ it all sorted out.
- [Django]-Specifying limit and offset in Django QuerySet wont work
- [Django]-How to test auto_now_add in django
- [Django]-Django 1.7 β App 'your_app_name' does not have migrations
0π
Be careful with your primary key datatype. In my case, i mistakently used int instead str.
if pk is string,
path('addesm/pending/<str:pk>', views.addesm, name='add ESM')
- [Django]-How can I serialize a queryset from an unrelated model as a nested serializer?
- [Django]-Disabled field is not passed through β workaround needed
- [Django]-What does 'many = True' do in Django Rest FrameWork?