File: urls.py

package info (click to toggle)
python-pytest-djangoapp 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 396 kB
  • sloc: python: 1,116; makefile: 114; sh: 6
file content (32 lines) | stat: -rw-r--r-- 829 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
try:
    from django.urls import re_path
    
except ImportError:
    from django.conf.urls import url as re_path

    
from django.http import HttpResponse

from pytest_djangoapp.compat import get_urlpatterns


def raise_exception(request):
    raise Exception('This one should be handled by 500 technical view')


def index(request, some_id):

    if request.method == 'POST':
        return HttpResponse('json')

    if request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest':  # .headers in Django 2.2+
        return HttpResponse('ajaxed')

    from django.templatetags.static import static
    return HttpResponse(f"{some_id} | fine {static('blank.png')}")


urlpatterns = get_urlpatterns([
    re_path(r'^index/(?P<some_id>\d+)/$', index, name='index'),
    re_path(r'^raiser/$', raise_exception, name='raiser'),
])