Ticket #16976: testcase.py

File testcase.py, 1.2 KB (added by Anton Morozov, 13 years ago)

Test case micro project

Line 
1from django.conf.urls.defaults import patterns
2from django.http import HttpResponse
3from django.template import RequestContext, Template
4
5template = """
6<script src="//yandex.st/jquery/1.6.2/jquery.min.js"></script>
7<script>
8$(function() {
9 $('#ajax_get, #ajax_post').click(function(e) {
10 e.preventDefault();
11 var id = this.id;
12 $.ajax({
13 //type: (id == 'ajax_post') ? 'POST' : 'GET',
14 type: 'POST',
15 url: '/ajax/',
16 cache: false,
17 data: {csrfmiddlewaretoken: '{{ csrf_token }}'},
18 success: function(data) {alert(data);},
19 error: function(e) {alert(e.status);}
20 });
21 });
22});
23</script>
24HTTP_REFERER: {{ request.META.HTTP_REFERER }}<br>
25HTTP_HOST: {{ request.META.HTTP_HOST }}<br>
26<a href="">Get referer</a><br>
27<a href="" id="ajax_get">Ajax GET request</a>
28<a href="" id="ajax_post">Ajax POST request</a>
29"""
30
31def index(request):
32 t = Template(template)
33 return HttpResponse(t.render(RequestContext(request, {'request': request})))
34
35def ajax(request):
36 return HttpResponse('HTTP_REFERER: %s\nHTTP_HOST: %s' % (request.META.get('HTTP_REFERER', ''), request.META['HTTP_HOST']))
37
38urlpatterns = patterns('',
39 (r'^$', index),
40 (r'^ajax/$', ajax),
41)
Back to Top