Q:

Django: View with conditional login_required

Given the view, latest_objs, I wanted the view to require login conditionally if there is a parameter in the URL.
The goal: 

If the URL passed is latest-objs, then return the non-authentication view with objs not related to any specific users.
If the URL passed is latest-objs/mine, I want to require login if the user isn't authenticated, as that version of the view is supposed to return objs related to the authenticated user.

Questions:

Is the right way to do this to check request.GET.get('some-param')?
How would I define these two scenarios in my urls.py file? Current I have this:
url(r'latest-objs', views.latest_objs, name='latest_objs'),

A little off-topic: I'm wondering if it's worth bothering with this, or simply creating two different views.

A:

You use request.GET when your URL has a querystring, e.g. /latest-objs?owner=me.
For a URL /latest-objs/mine, you have to modify your URL pattern, or add a new one. I prefer to add a new URL pattern because I think it's more readable. You can either use a new view,
url(r'latest-objs/mine', views.my_objs, name='my_objs'),

or use the same view, and pass mine to the view so that you can tell which URL pattern was matched.
url(r'latest-objs/mine', views.latest_objs, {'mine': True}, name='my_objs'),

If you go for the later approach, then you need to update the view to accept mine as an argument.
def latest_objs(request, mine=False):
    ...

Whether you reuse the same view or a different view is a matter of judgement, and in my opinion it depends on the views. For a simple view, a separate view would be most straight forward, since you can then use the login required decorator or mixins to handle the redirect. For a more complex view, a separate view might lead to duplicated code.

