Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gregschmit/b1787d9f4d0b4b6c9a18f15608d15159 to your computer and use it in GitHub Desktop.
Save gregschmit/b1787d9f4d0b4b6c9a18f15608d15159 to your computer and use it in GitHub Desktop.
django_profiler.py
from django.contrib.auth.models import User
from django.core.urlresolvers import resolve
from django.test import RequestFactory
def profile_request(url='/', username='gschmit'):
# perform a GET for the profiler
u = User.objects.get(username=username)
rf = RequestFactory()
request = rf.get(url)
request.user = u
match = resolve(url)
response = match.func(request)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment