Login

Tag "views"

Snippet List

Simple views method binding

@match_func_by_method def frontpage (request) : pass def get_frontpage (request, argument, ) : # GET things pass def post_frontpage (request, argument, ) : # POST things pass

  • views
  • http-method
Read More

require XMLHttpRequest view decorator

Decorator to make a view only accept requests from AJAX calls. Usage:: @require_xhr() def my_view(request): # Returns data # ... by [skam](http://skam.webfactional.com/)

  • ajax
  • views
  • view
  • decorator
  • decorators
  • xhr
  • xmlhttprequest
Read More

Decorating urlpatterns

One thing I wanted for a while was the ability to basically apply something like @login_required to a bunch of urlpatterns in one go, instead of having to decorate each and every view manually. In this example, the latter two views will always raise a 404.

  • urls
  • views
  • decorators
  • urlpatterns
Read More

Pagination for date-based views

Date-based generic views do not provide pagination by default but Django is very extensible. It provides a Paginator that takes care of pagination. Since date based views usually order by descending order ie from latest entry to the oldest, I used a queryset to order the items (on a field called 'date_pub') and then pass this queryset to the paginator which takes care of the pagination.

  • views
  • date
  • pagination
Read More

Serving null files

Sometimes you have to serve null files. This quick hacky generic view lets you do that. The best example of that is robots.txt, I want my robots.txt to always be empty, at least for now. The other example would be favicon.ico, but that's more often used to actually fill a purpose.

  • null
  • files
  • views
Read More

35 snippets posted so far.