Code

#19889 closed Cleanup/optimization (needsinfo)

Tutorial03 makes you refactor code that you cannot run

Reported by: jpic Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords:
Cc: jpic Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

  1. Writing more views introduces polls.views.detail code that is testable with runserver:
    def detail(request, poll_id):
        return HttpResponse("You're looking at poll %s." % poll_id)
  1. Then, Raising 404 error introduces a new version of this view:
def detail(request, poll_id):
    try:
        poll = Poll.objects.get(pk=poll_id)
    except Poll.DoesNotExist:
        raise Http404
    return render(request, 'polls/detail.html', {'poll': poll})

(Which you cannot test yet because you don't have polls/detail.html)

  1. Then, this view code changes in A shortcut: get_object_or_404.
  1. Then, and only then, the tutorial makes you create polls/details.html in Use the template system.

I think it's a problem that you code something in step 2., change it in step 3., but are able to test it only after step 4. Shouldn't the app be run-able at every step ?

Attachments (0)

Change History (6)

comment:1 Changed 14 months ago by jpic

  • Cc jpic added
  • Easy pickings set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Type changed from Uncategorized to Cleanup/optimization

comment:2 Changed 14 months ago by timo

Well, below [1] it does say:

We’ll discuss what you could put in that polls/detail.html template a bit later, but if you’d like to quickly get the above example working, just:

{{ poll }}

will get you started for now.

What's your suggestion for how to improve it?

comment:3 Changed 14 months ago by ptone

I might change

"working, just:"

to

"working, a file containing just:"

But otherwise - yes, you can't cover everything simultaneously.

comment:4 Changed 14 months ago by Preston Holmes <preston@…>

In f60dd6f55dcd646dcec4f7f8b2cc73af985ccba3:

[1.5.x] Made a small clarification in tutorial.

refs #19889

comment:5 Changed 14 months ago by Preston Holmes <preston@…>

In 17a28b39a8d77997f83ecd94ebcff7b198b8cb05:

Made a small clarification in tutorial.

refs #19889

comment:6 Changed 14 months ago by ptone

  • Resolution set to needsinfo
  • Status changed from new to closed

I made the small clarification - going to close as needs info, if the ticket author can provide some other concrete suggestions for improvement, by all means - please reopen.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.