Problem with my view or template (DRIVES ME NUTS)

20 views
Skip to first unread message

leaks

unread,
Mar 5, 2012, 9:54:55 AM3/5/12
to django...@googlegroups.com
I don't get an error... Nothing just happens

my view: (I think the problem is here)

def push(request, pk):
    if request.method == 'POST':
        entry = Entry.objects.get(pk=pk)
        entry.pushes +=1
        entry.save()

My template:

<ul>
{% for entry in entries.object_list %}
<li><a href="{{ entry.link }}" >{{ entry.title }}</a>
Posted on {{ entry.posted }} by {{ entry.submitter }} | pushed {{ entry.pushes }} time(s).
{% if user.is_authenticated %}
#or maybe here...
<form action="." method="POST">
{% csrf_token %}
<input type="submit" value="Push">
</form>
</li>
{% endfor %}
</ul>

This is my first project and i haven't really understood how GET and POST request's work with models...

Thanks in advance :)

Ilian Iliev

unread,
Mar 5, 2012, 10:13:14 AM3/5/12
to django...@googlegroups.com
Hi,

first of all use if request.POST, second pehaps you should pass the pk as part of the action URL.
Do you get any errors or anything?


--
eng. Ilian Iliev
Web Software Developer

Mobile: +359 88 66 08 400
Website: http://ilian.i-n-i.org


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/8GXXgG28NcQJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



leaks

unread,
Mar 5, 2012, 10:24:14 AM3/5/12
to django...@googlegroups.com
no, no errors get displayed... Just nothing happens. Do you mean passing the pk in my url?
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.

Tom Evans

unread,
Mar 5, 2012, 10:35:29 AM3/5/12
to django...@googlegroups.com
On Mon, Mar 5, 2012 at 3:24 PM, leaks <tonykyr...@gmail.com> wrote:
> no, no errors get displayed... Just nothing happens.

Absolutely and literally 'nothing happens'? Really?

Does the browser submit the form, django receive a request and render
a response? I would definitely class that as 'something' and not
'nothing'.

We can only help you if you help us. You need to explain precisely
what happens, and what you expected to happen. Saying 'nothing
happens' is nonsense, and perhaps if you had investigated what was
actually happening, you may have understood why it didn't happen as
you expected, rather than expecting us to magically deduce both things
from the ether.

Cheers

Tom

Bill Freeman

unread,
Mar 5, 2012, 10:52:50 AM3/5/12
to django...@googlegroups.com
If that's your complete view, you've forgotten to return an HTTPResponse object.

Since action='.', it appears that you are using the same view to get
the form and to
post (which is fine), but each case must return a response for the
prowser, presumably
rendered from the same template. The render_to_response() shortcut is
your friend
here.

Also, while not required, it is usual for a successful post to
actually return a redirect to
a separate success view (helps guard, I believe, against inadvertent
double submits).

> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.

> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to

> django-users...@googlegroups.com.

leaks

unread,
Mar 5, 2012, 11:00:20 AM3/5/12
to django...@googlegroups.com
dHey tom... The homepage displays a list of entries posted by users... Each entry has a submit button next to it, I watched many tutorials and i still dont get how those requests work...

I made the view as above and the main idea is to add +1 to my "pushes"(my model has a pushes field wich is an integer field). Plus I don't want it to leave the page. That's why i didn't add a render_to_response()

I created the form as above, and when i click on the submit button it doesn't do anything at all, well it shows it refreshed the page but it didn't add a +1 neither an error occurs

leaks

unread,
Mar 5, 2012, 11:13:55 AM3/5/12
to django...@googlegroups.com
Tried HttpResponseRedirect('/') and still nothing happens. Thanks

> django-users+unsubscribe@googlegroups.com.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages