Thursday, May 3, 2018

Re: Working through the Django tutorial and have run into a problem I cannot figure out. Help would be appreciated. What am I missing here? whenever is search the url "http://127.0.0.1:8000/polls/" the site refused to connect and in command prompt many e

thank you Anthony, now i will try your code and i am sure it will run this time

On Thu, May 3, 2018 at 10:37 PM, 'Anthony Flury' via Django users <django-users@googlegroups.com> wrote:
I think the root cause of the errors was due to an incorrect settings - but Fidel is right that your views.py wasn't great either.

On 03/05/18 17:36, Avitab Ayan Sarmah wrote:
thank you Fidel, and i will take care of it

On Thu, May 3, 2018 at 9:57 PM, Fidel Leon <fidel@flm.cat <mailto:fidel@flm.cat>> wrote:

    Sure:

    from django.http import HttpResponse

    from .models import Question


    def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
        output = ', '.join([q.question_text for q in
    latest_question_list])
        return HttpResponse(output)

    def detail(request, question_id):
    return HttpResponse("You're looking at question %s." % question_id)

    def results(request, question_id):
    response = "You're looking at the results of question %s."
    return HttpResponse(response % question_id)

    def vote(request, question_id):
    return HttpResponse("You're voting on question %s." % question_id)

    As a matter of advice, please use a fixed-width font when pasting
    code, because Python is indented with spaces and using any other
    type of font makes reading your mail difficult :)

    El jue., 3 may. 2018 a las 18:08, Avitab Ayan Sarmah
    (<avitabayans@gmail.com <mailto:avitabayans@gmail.com>>) escribió:

        hello Fidel Leon can you please rewrite the whole views.py
        code so that i can understand what is the exact code is

        On Thu, May 3, 2018 at 9:19 PM, Fidel Leon <fidel@flm.cat
        <mailto:fidel@flm.cat>> wrote:



            El jue., 3 may. 2018 a las 17:38, Avitab Ayan Sarmah
            (<avitabayans@gmail.com <mailto:avitabayans@gmail.com>>)
            escribió:


                *polls/views.py*:


                from django.http import HttpResponse
                from django.template import loader

                from . models import Question

                def index(request):
                return HttpResponse("Hello, world.You're at the polls
                index.")
                latest_question_list =
                Question.objects.order_by('-pub_date')[:5]
                output = ', '.join([q.question_text for q in
                latest_question_list])
                return HttpResponse(output)
                latest_question_list =
                Question.objects.order_by('-pub_date')[:5]
                template = loader.get_template('polls/index.html')
                context = {
                'latest_question_list': latest_question_list,
                }
                return HttpResponse(template.render(context, request))


            Your function index(request) inside polls/views.py is
            badly written (you have three function returns). Seems you
            are following the tutorial but not removing the previous
            examples:

            def index(request):
              latest_question_list =
            Question.objects.order_by('-pub_date')[:5]
              context = {'latest_question_list': latest_question_list}
              return render(request, 'polls/index.html', context)

            --             Fidel Leon
            fidel@flm.cat <mailto:fidel@flm.cat>

            --             You received this message because you are subscribed to a
            topic in the Google Groups "Django users" group.
            To unsubscribe from this topic, visit
            https://groups.google.com/d/topic/django-users/5hvN4Lfds-w/unsubscribe
            <https://groups.google.com/d/topic/django-users/5hvN4Lfds-w/unsubscribe>.
            To unsubscribe from this group and all its topics, send an
            email to django-users+unsubscribe@googlegroups.com
            <mailto:django-users+unsubscribe@googlegroups.com>.
            To post to this group, send email to
            django-users@googlegroups.com
            <mailto:django-users@googlegroups.com>.
            Visit this group at
            https://groups.google.com/group/django-users
            <https://groups.google.com/group/django-users>.
            To view this discussion on the web visit
            https://groups.google.com/d/msgid/django-users/CAHXg%3DN2SNuyAsAzk7mYfBB5rahtD3fRSa4vTbL92BQf5CHg-Nw%40mail.gmail.com
            <https://groups.google.com/d/msgid/django-users/CAHXg%3DN2SNuyAsAzk7mYfBB5rahtD3fRSa4vTbL92BQf5CHg-Nw%40mail.gmail.com?utm_medium=email&utm_source=footer>.


            For more options, visit https://groups.google.com/d/optout
            <https://groups.google.com/d/optout>.


        --         You received this message because you are subscribed to the
        Google Groups "Django users" group.
        To unsubscribe from this group and stop receiving emails from
        it, send an email to django-users+unsubscribe@googlegroups.com
        <mailto:django-users+unsubscribe@googlegroups.com>.
        To post to this group, send email to
        django-users@googlegroups.com
        <mailto:django-users@googlegroups.com>.
        Visit this group at
        https://groups.google.com/group/django-users
        <https://groups.google.com/group/django-users>.
        To view this discussion on the web visit
        https://groups.google.com/d/msgid/django-users/CAEx5wm7VMMa3C2%3DyWA%3DQu%3DhihJiWujwvoA59Xx4ru59Zdc0UVg%40mail.gmail.com
        <https://groups.google.com/d/msgid/django-users/CAEx5wm7VMMa3C2%3DyWA%3DQu%3DhihJiWujwvoA59Xx4ru59Zdc0UVg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
        For more options, visit https://groups.google.com/d/optout
        <https://groups.google.com/d/optout>.



    --     Fidel Leon
    fidel@flm.cat <mailto:fidel@flm.cat>
    Phone: +34 622 26 44 92
    --     You received this message because you are subscribed to a topic in
    the Google Groups "Django users" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/django-users/5hvN4Lfds-w/unsubscribe
    <https://groups.google.com/d/topic/django-users/5hvN4Lfds-w/unsubscribe>.
    To unsubscribe from this group and all its topics, send an email
    to django-users+unsubscribe@googlegroups.com
    <mailto:django-users+unsubscribe@googlegroups.com>.
    To post to this group, send email to django-users@googlegroups.com
    <mailto:django-users@googlegroups.com>.
    Visit this group at https://groups.google.com/group/django-users
    <https://groups.google.com/group/django-users>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/django-users/CAHXg%3DN3-8kKboqLD8cFRympuLvtTgj0uh6BxbfMr8FtfyNEojA%40mail.gmail.com
    <https://groups.google.com/d/msgid/django-users/CAHXg%3DN3-8kKboqLD8cFRympuLvtTgj0uh6BxbfMr8FtfyNEojA%40mail.gmail.com?utm_medium=email&utm_source=footer>.


    For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com <mailto:django-users+unsubscribe@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com <mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEx5wm6dhT3ZLPvKcFObV1Po26w82b3u%3DwFoj7GQm_iYUg2xzw%40mail.gmail.com <https://groups.google.com/d/msgid/django-users/CAEx5wm6dhT3ZLPvKcFObV1Po26w82b3u%3DwFoj7GQm_iYUg2xzw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
--
Anthony Flury
email : *Anthony.flury@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/5hvN4Lfds-w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4906b240-8140-e303-a41d-1aad98b5cebb%40btinternet.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEx5wm6q36gXY3f0-ng16Z49xCjTe7%3DoHVxVhYb4-XnvZ_io0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment