On Sat, Feb 15, 2014 at 10:47 PM, Andrew Taylor <andydtay...@gmail.com>wrote:

> Hi,
>
> I've been following an online tutorial but been debugging. I've traced my
> issue to this line in the view function below:
>
> return category(request, category_name_url)
>
>
> Is this view effectively calling another view directly without going via
> the urls file (in the exception case)? If so can you advise me if this is
> good or bad practice?
>
> As with all interesting questions, the answer is "it depends" - but
broadly speaking, it isn't inherently bad practice.

At the end of the day, a view is just a function. It's a function with a
very specific prototype -- first argument is a request object, returns a
HttpResponse -- but otherwise, it's just a normal function. All the normal
rules about functional composition apply.

So - if you've got a base piece of functionality for which a "view" is the
natural interface, but you've got a larger piece of functionality that is
the "base" plus some extra logic, calling a view as a function is entirely
good practice. A good example -- a basic view that manipulates data in some
way; and a larger function that does some permissions checks before calling
the base functionality and returning the expected result.

It isn't universal true, of course; there will always be occasions where
calling a view isn't the right thing to do, but that will have more to do
with broader software engineering principles about functional decomposition
than the specifics of calling a view.

Hope that helps!

Yours,
Russ Magee %-)

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq84_r2fGo%3D4mvoa4PRtEFaRq7qdQ%3D5WRM9E65NZ%2BOtU%2BBGQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to