当前位置: 首页>>代码示例>>Python>>正文


Python django.http方法代码示例

本文整理汇总了Python中django.http方法的典型用法代码示例。如果您正苦于以下问题:Python django.http方法的具体用法?Python django.http怎么用?Python django.http使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django的用法示例。


在下文中一共展示了django.http方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: login

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def login(request):

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    #                                                                         #
    #  GET  : Return the HTML template used for logging in a User             #
    #                                                                         #
    #  POST : Attempt to login the User and authenticate their credentials.   #
    #         If their login is invalid, let them know. In all cases, return  #
    #         the User back to the main page                                  #
    #                                                                         #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

    if request.method == 'GET':
        return render(request, 'login.html')

    user = django.contrib.auth.authenticate(
        username=request.POST['username'],
        password=request.POST['password'])

    if user is None:
        return index(request, error='Unable to Authenticate User')

    django.contrib.auth.login(request, user)
    return django.http.HttpResponseRedirect('/index/') 
开发者ID:AndyGrant,项目名称:OpenBench,代码行数:26,代码来源:views.py

示例2: About

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def About(request):
  """About page."""
  overview = """These tests cover browers' implementations of 
  <a href="http://blog.whatwg.org/the-road-to-html-5-contenteditable">contenteditable</a>
  for basic rich text formatting commands. Most browser implementations do very
  well at editing the HTML which is generated by their own execCommands. But a
  big problem happens when developers try to make cross-browser web
  applications using contenteditable - most browsers are not able to correctly
  change formatting generated by other browsers. On top of that, most browsers
  allow users to to paste arbitrary HTML from other webpages into a
  contenteditable region, which is even harder for browsers to properly
  format. These tests check how well the execCommand, queryCommandState,
  and queryCommandValue functions work with different types of HTML. Please
  note that these are WYSIWYG editing tests, not semantic editing tests. Any
  HTML which produces a given visual style should be changeable via the
  execCommand for that style."""
  return util.About(request, CATEGORY, category_title='Rich Text',
                    overview=overview, show_hidden=False) 
开发者ID:elsigh,项目名称:browserscope,代码行数:20,代码来源:handlers.py

示例3: default_idtoken_processing_hook

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def default_idtoken_processing_hook(
        id_token, user, token, request, **kwargs):
    """
    Hook to perform some additional actions to `id_token` dictionary just before serialization.

    :param id_token: dictionary contains values that going to be serialized into `id_token`
    :type id_token: dict

    :param user: user for whom id_token is generated
    :type user: User

    :param token: the Token object created for the authentication request
    :type token: oidc_provider.models.Token

    :param request: the request initiating this ID token processing
    :type request: django.http.HttpRequest

    :return: custom modified dictionary of values for `id_token`
    :rtype: dict
    """
    return id_token 
开发者ID:juanifioren,项目名称:django-oidc-provider,代码行数:23,代码来源:common.py

示例4: test_create_notification

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def test_create_notification(self, mock_reverse, mock_router):
        request = self._make_request('POST', {'nickname': 'Rover', 'color': 'brown'})
        mock_reverse.return_value = '/dogs/2/'
        mock_router.registry = [('dogs', None, 'dummy')]

        response = self.view(request)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(request._messagings,
                         [('.dogs.added', {
                             'url': 'http://0.0.0.0/dogs/2/',
                             'new_value': {
                                 'color': 'brown',
                                 'nickname': 'Rover'
                             },
                         })])
        self.assertEqual(mock_reverse.call_args_list,
                         [mock.call('dummy-detail', args=[2])]) 
开发者ID:product-definition-center,项目名称:product-definition-center,代码行数:20,代码来源:tests.py

示例5: test_update_notification

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def test_update_notification(self, mock_reverse, mock_router):
        request = self._make_request('PUT', {'nickname': 'Fido', 'color': 'golden'})
        mock_reverse.return_value = '/dogs/1/'
        mock_router.registry = [('dogs', None, 'dummy')]

        response = self.view(request)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(request._messagings,
                         [('.dogs.changed', {
                             'url': 'http://0.0.0.0/dogs/1/',
                             'new_value': {
                                 'color': 'golden',
                                 'nickname': 'Fido'
                             },
                             'old_value': {
                                 'color': 'black',
                                 'nickname': 'Spot'
                             },
                         })])
        self.assertEqual(mock_reverse.call_args_list,
                         [mock.call('dummy-detail', args=[1])]) 
开发者ID:product-definition-center,项目名称:product-definition-center,代码行数:24,代码来源:tests.py

示例6: test_get_input

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def test_get_input(self):
        r = django.http.HttpRequest()
        r.GET = django.http.QueryDict('foo=bar')
        r.POST = django.http.QueryDict('foo=bar')
        r.COOKIES = {'foo': 'bar'}
        r.META = {'HTTP_FOO': 'bar', 'foo': 'bar'}

        i = shadowd.django_connector.InputDjango(r)
        i.gather_input()

        input = i.get_input()
        self.assertIn('GET|foo', input)
        self.assertEqual(input['GET|foo'], 'bar')
        self.assertIn('POST|foo', input)
        self.assertEqual(input['POST|foo'], 'bar')
        self.assertIn('COOKIE|foo', input)
        self.assertEqual(input['COOKIE|foo'], 'bar')
        self.assertIn('SERVER|HTTP_FOO', input)
        self.assertEqual(input['SERVER|HTTP_FOO'], 'bar')
        self.assertNotIn('SERVER|foo', input) 
开发者ID:zecure,项目名称:shadowd_python,代码行数:22,代码来源:test_django_connector.py

示例7: test_get_input_array

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def test_get_input_array(self):
        r = django.http.HttpRequest()
        r.GET = django.http.QueryDict('foo=bar1&foo=bar2')
        r.POST = django.http.QueryDict('foo=bar1&foo=bar2')

        i = shadowd.django_connector.InputDjango(r)
        i.gather_input()

        input = i.get_input()
        self.assertIn('GET|foo|0', input)
        self.assertEqual(input['GET|foo|0'], 'bar1')
        self.assertIn('GET|foo|1', input)
        self.assertEqual(input['GET|foo|1'], 'bar2')
        self.assertIn('POST|foo|0', input)
        self.assertEqual(input['POST|foo|0'], 'bar1')
        self.assertIn('POST|foo|1', input)
        self.assertEqual(input['POST|foo|1'], 'bar2') 
开发者ID:zecure,项目名称:shadowd_python,代码行数:19,代码来源:test_django_connector.py

示例8: test_defuse_input

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def test_defuse_input(self):
        r = django.http.HttpRequest()
        r.GET = django.http.QueryDict('foo=bar')
        r.POST = django.http.QueryDict('foo=bar')
        r.COOKIES = {'foo': 'bar'}
        r.META = {'HTTP_FOO': 'bar'}

        i = shadowd.django_connector.InputDjango(r)

        threats1 = ['GET|foo', 'POST|foo', 'COOKIE|foo', 'SERVER|HTTP_FOO']
        self.assertTrue(i.defuse_input(threats1))
        self.assertIn('foo', r.GET)
        self.assertEqual(r.GET['foo'], '')
        self.assertIn('foo', r.POST)
        self.assertEqual(r.POST['foo'], '')
        self.assertIn('foo', r.COOKIES)
        self.assertEqual(r.COOKIES['foo'], '')
        self.assertIn('HTTP_FOO', r.META)
        self.assertEqual(r.META['HTTP_FOO'], '')

        threats2 = ['FILES|foo']
        self.assertFalse(i.defuse_input(threats2)) 
开发者ID:zecure,项目名称:shadowd_python,代码行数:24,代码来源:test_django_connector.py

示例9: build_absolute_uri

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def build_absolute_uri(self, path=None, repo=None, params=None):
        """Builds an absolute URI given a path.

        See build_absolute_path (above) for an explanation of why we implement
        this function ourselves.

        Args:
            path (str, optional): A path beginning with a slash (may include a
                query string), e.g., '/abc?x=y'. If the path argument is not
                specified or is None, the current request's path will be used.
            repo (str, optional): A repo ID. If specified, the path will be
                considered relative to the repo's route. If this is specified,
                path must also be specified.
            params (list, optional): A list of tuples of query param keys and
                values to add to the path.

        Returns:
            str: An absolute URI, including the sitewide OPTIONAL_PATH_PREFIX if
            it was used with the original request (e.g.,
            'http://localhost:8000/personfinder/abc?x=y'). Does not preserve
            query parameters from the original request.
        """
        return self.request.build_absolute_uri(
            self.build_absolute_path(path, repo, params)) 
开发者ID:google,项目名称:personfinder,代码行数:26,代码来源:base.py

示例10: post

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def post(self, request, *args, **kwargs):
        del request, args, kwargs  # unused
        query = model.Person.all(filter_expired=False).filter(
            'repo =', self.env.repo)
        cursor = self.params.cursor
        if cursor:
            query.with_cursor(cursor)
        try:
            for person in query:
                next_cursor = query.cursor()
                self._check_person(person)
                cursor = next_cursor
        except runtime.DeadlineExceededError:
            self.schedule_task(self.env.repo, cursor=cursor)
        except datastore_errors.Timeout:
            self.schedule_task(self.env.repo, cursor=cursor)
        return django.http.HttpResponse('') 
开发者ID:google,项目名称:personfinder,代码行数:19,代码来源:datachecks.py

示例11: dispatch

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def dispatch(self, request, *args, **kwargs):
        """See docs on django.views.View.dispatch."""
        # If the X-AppEngine-TaskQueue header is set, it means the request came
        # from App Engine, not an external user:
        # https://cloud.google.com/appengine/docs/standard/python/taskqueue/push/creating-handlers#reading_request_headers
        # There are various reasons we'd prefer to prevent external users from
        # starting up tasks (e.g., because some tasks might be expensive
        # operations).
        # Django renames headers, so X-AppEngine-TaskName will be in the META
        # dictionary as HTTP_X_APPENGINE_TASKNAME:
        # https://docs.djangoproject.com/en/1.11/ref/request-response/#django.http.HttpRequest.META
        if not (request.META.get('HTTP_X_APPENGINE_TASKNAME') or
                utils.is_dev_app_server()):
            logging.warn('Non-taskqueue access of: %s' % self.request.path)
            return self.error(403)
        return super(TasksBaseView, self).dispatch(request, args, kwargs) 
开发者ID:google,项目名称:personfinder,代码行数:18,代码来源:base.py

示例12: post

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def post(self, request, *args, **kwargs):
        del request, args, kwargs  # unused
        q = self.get_query()
        cursor = self.params.get('cursor', '')
        if cursor:
            q.with_cursor(cursor)
        try:
            now = utils.get_utcnow()
            for item in q:
                next_cursor = q.cursor()
                associated_person = model.Person.get(
                    self.env.repo, self.get_person_record_id(item))
                if not associated_person:
                    if now - self.get_base_timestamp(item) > _STRAY_CLEANUP_TTL:
                        db.delete(item)
                cursor = next_cursor
        except runtime.DeadlineExceededError:
            self.schedule_task(self.env.repo, cursor=cursor)
        except datastore_errors.Timeout:
            self.schedule_task(self.env.repo, cursor=cursor)
        return django.http.HttpResponse('') 
开发者ID:google,项目名称:personfinder,代码行数:23,代码来源:deletion.py

示例13: test_accept_note

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def test_accept_note(self):
        """Tests POST requests to accept a note."""
        note = self.data_generator.note(person_id=self.person.record_id)
        get_doc = self.to_doc(self.client.get(
            '/haiti/admin/review/', secure=True))
        xsrf_token = get_doc.cssselect_one('input[name="xsrf_token"]').get(
            'value')
        post_resp = self.client.post('/haiti/admin/review/', {
            'note.%s' % note.record_id: 'accept',
            'xsrf_token': xsrf_token,
        }, secure=True)
        # Check that the user's redirected to the repo's main admin page.
        self.assertIsInstance(post_resp, django.http.HttpResponseRedirect)
        self.assertEqual(post_resp.url, '/haiti/admin/review/')
        # Reload the Note from Datastore.
        note = model.Note.get('haiti', note.record_id)
        self.assertIs(note.reviewed, True)
        self.assertIs(note.hidden, False) 
开发者ID:google,项目名称:personfinder,代码行数:20,代码来源:test_admin_review.py

示例14: test_flag_note

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def test_flag_note(self):
        """Tests POST requests to flag a note."""
        note = self.data_generator.note(person_id=self.person.record_id)
        get_doc = self.to_doc(self.client.get(
            '/haiti/admin/review/', secure=True))
        xsrf_token = get_doc.cssselect_one('input[name="xsrf_token"]').get(
            'value')
        post_resp = self.client.post('/haiti/admin/review/', {
            'note.%s' % note.record_id: 'flag',
            'xsrf_token': xsrf_token,
        }, secure=True)
        # Check that the user's redirected to the repo's main admin page.
        self.assertIsInstance(post_resp, django.http.HttpResponseRedirect)
        self.assertEqual(post_resp.url, '/haiti/admin/review/')
        # Reload the Note from Datastore.
        note = model.Note.get('haiti', note.record_id)
        self.assertIs(note.reviewed, True)
        self.assertIs(note.hidden, True) 
开发者ID:google,项目名称:personfinder,代码行数:20,代码来源:test_admin_review.py

示例15: test_post

# 需要导入模块: import django [as 别名]
# 或者: from django import http [as 别名]
def test_post(self):
        """Tests POST requests to delete a record."""
        get_doc = self.to_doc(self.client.get(
            '/global/admin/delete_record/', secure=True))
        xsrf_token = get_doc.cssselect_one('input[name="xsrf_token"]').get(
            'value')
        post_resp = self.client.post('/haiti/admin/delete_record/', {
            'xsrf_token': xsrf_token,
            'id': self.person.record_id,
        }, secure=True)
        # Check that the user's redirected to the repo's main admin page.
        self.assertIsInstance(post_resp, django.http.HttpResponseRedirect)
        parse = urlparse.urlparse(post_resp.url)
        self.assertEqual('/haiti/delete', parse.path)
        query_params = dict(urlparse.parse_qsl(parse.query))
        self.assertEqual(query_params['id'], self.person.record_id)
        # Check that the signature param is present and not the empty string.
        self.assertTrue(len(query_params['signature']) > 1) 
开发者ID:google,项目名称:personfinder,代码行数:20,代码来源:test_admin_delete_record.py


注:本文中的django.http方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。