Re: help to finish my 1st Django app.

2011-03-15 Thread Igor Ischenko
Or you can simply use object_list instead of latest_poll_list

2011/3/15 christian.posta 

> Your template file checks to see whether a variable named
> "latest_poll_list" exists.
> I don't see anywhere in your views where you add this to your context.
> Look at part 3 of the tutorial about half way down. They add the
> "latest_poll_list" object to the Context that gets passed to your
> template. Try doing that.
>
> On Mar 14, 4:26 pm, Rogelio Gonzalez  wrote:
> > Hi Igor.
> >
> > Thanks for your reply. My poll_list.html code is:
> >
> > {% if latest_poll_list %}
> > 
> > {% for poll in latest_poll_list %}
> > {{ poll.question }}
> > {% endfor %}
> > 
> > {% else %}
> > No polls are available.
> > {% endif %}
> > What i'm doing wrong?..
> >
> > 2011/3/14 royy 
> >
> >
> >
> >
> >
> >
> >
> > > Hi.
> >
> > > I've finished the tutorial for the polls app.
> >
> > > I tought everythin was OK till I load the server and type the addres:
> > >http://127.0.0.1:8000/polls/
> >
> > > web browser shows me the message "No polls are available" isn't a web
> > > browser error message, because it is plain text.
> >
> > > I've created 3 polls with 3 choices each one.
> >
> > > admin page works fine, just the polls address is the one that don't
> > > loads well. This is my final views.py code:
> >
> > > from django.shortcuts import get_object_or_404, render_to_response
> > > from django.http import HttpResponseRedirect, HttpResponse
> > > from django.core.urlresolvers import reverse
> > > from django.template import RequestContext
> > > from polls.models import Choice, Poll
> >
> > > def vote(request, poll_id):
> > >p = get_object_or_404(Poll, pk=poll_id)
> > >try:
> > >selected_choice = p.choice_set.get(pk=request.POST['choice'])
> > >except (KeyError, Choice.DoesNotExist):
> >
> > >return render_to_response('polls/poll_detail.html', {
> > >'poll': p,
> > >'error_message': "You didn't select a choice.",
> > >}, context_instance=RequestContext(request))
> > >else:
> > >selected_choice.votes += 1
> > >selected_choice.save()
> > >return HttpResponseRedirect(reverse('poll_results',
> > > args=(p.id,)))
> >
> > >
> ---
> --
> >
> > > and this is my final polls/urls.py code:
> >
> > > from django.conf.urls.defaults import *
> > > from polls.models import Poll
> >
> > > info_dict = {
> > >'queryset': Poll.objects.all(),
> > > }
> >
> > > urlpatterns = patterns('',
> > >(r'^$', 'django.views.generic.list_detail.object_list',
> > > info_dict),
> > >(r'^(?P\d+)/$',
> > > 'django.views.generic.list_detail.object_detail', info_dict),
> > >url(r'^(?P\d+)/results/$',
> > > 'django.views.generic.list_detail.object_detail', dict(info_dict,
> > > template_name='polls/results.html'), 'poll_results'),
> > >(r'^(?P\d+)/vote/$', 'polls.views.vote'),
> > > )
> >
> > > Please help me to find what's wrong.
> >
> > > Thanks
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Django users" group.
> > > To post to this group, send email to django-users@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Best regards,
Igor Ishchenko

iPhone dev team
NIX Solutions, Ltd.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: help to finish my 1st Django app.

2011-03-14 Thread Igor Ischenko
Hi

Show your template file

2011/3/14 royy 

> Hi.
>
> I've finished the tutorial for the polls app.
>
> I tought everythin was OK till I load the server and type the addres:
> http://127.0.0.1:8000/polls/
>
> web browser shows me the message "No polls are available" isn't a web
> browser error message, because it is plain text.
>
> I've created 3 polls with 3 choices each one.
>
> admin page works fine, just the polls address is the one that don't
> loads well. This is my final views.py code:
>
> from django.shortcuts import get_object_or_404, render_to_response
> from django.http import HttpResponseRedirect, HttpResponse
> from django.core.urlresolvers import reverse
> from django.template import RequestContext
> from polls.models import Choice, Poll
>
> def vote(request, poll_id):
>p = get_object_or_404(Poll, pk=poll_id)
>try:
>selected_choice = p.choice_set.get(pk=request.POST['choice'])
>except (KeyError, Choice.DoesNotExist):
>
>return render_to_response('polls/poll_detail.html', {
>'poll': p,
>'error_message': "You didn't select a choice.",
>}, context_instance=RequestContext(request))
>else:
>selected_choice.votes += 1
>selected_choice.save()
>return HttpResponseRedirect(reverse('poll_results',
> args=(p.id,)))
>
>
> -
>
> and this is my final polls/urls.py code:
>
> from django.conf.urls.defaults import *
> from polls.models import Poll
>
> info_dict = {
>'queryset': Poll.objects.all(),
> }
>
> urlpatterns = patterns('',
>(r'^$', 'django.views.generic.list_detail.object_list',
> info_dict),
>(r'^(?P\d+)/$',
> 'django.views.generic.list_detail.object_detail', info_dict),
>url(r'^(?P\d+)/results/$',
> 'django.views.generic.list_detail.object_detail', dict(info_dict,
> template_name='polls/results.html'), 'poll_results'),
>(r'^(?P\d+)/vote/$', 'polls.views.vote'),
> )
>
>
> Please help me to find what's wrong.
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Best regards,
Igor Ishchenko

iPhone dev team
NIX Solutions, Ltd.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to use CreateView?

2011-03-12 Thread Igor Ischenko
Hi hassan,

try to add {% csrf_token %} somewhere inside form in your template

On 11 мар, 23:41, hassan  wrote:
> Hi,
>
> I am testing django 1.3 class based generic views. I have a model like
> this one:
>
> class Book(models.Model):
>     name = models.CharField(max_length=50)
>     author = models.CharField(max_length=50)
>
> and in views.py:
>
> class BookUpdateView(CreateView):
>     model = Book
>     template_name = "create_book.html"
>
> and in create_book.html
> 
> ...
> 
> 
>
> But when i press the save button it form it does nothing!
> What's wrong with me?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.