Django 请求配置

http请求配置

请求流程

urls.py配置

复制代码
from first_app import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('test/',views.first_test),
]

views.py配置

复制代码
from django.shortcuts import render,HttpResponse

# Create your views here.
def first_test(request):
    print('第一个Django项目views')
    return HttpResponse('Django项目第一次请求成功')

启动服务

复制代码
python manage.py runserver

浏览器发送请求

其中在views.py文件中,每一个请求方法需要有一个request参数,通过该参数可以获取请求相应信息。可以使用dir(request)打印查看详细。

复制代码
['COOKIES', 'FILES', 'GET', 'META', 'POST', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', 
'__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_current_scheme_host', '_encoding', '_get_full_path', '_get_post', '_get_raw_host', 
'_get_scheme', '_initialize_handlers', '_load_post_and_files', '_mark_post_parse_error', '_messages', '_read_started', '_set_content_type_params', '_set_post', '_stream', '_upload_handlers', 'accepted_types', 'accepts', 'body', 'build_absolute_uri', 'close', 'content_params', 'content_type', 'csrf_processing_done', 'encoding', 'environ', 'get_full_path', 'get_full_path_info', 'get_host', 'get_port', 'get_raw_uri', 'get_signed_cookie', 'headers', 'is_ajax', 'is_secure', 'method', 'parse_file_upload', 'path', 'path_info', 'read', 'readline', 'readlines', 'resolver_match', 'scheme', 'session', 'upload_handlers', 'user']
相关推荐
金銀銅鐵7 分钟前
[Java] 用GUI展示class文件顶层的 access_flags
后端·python·ai编程
kimnoic28 分钟前
Python操作xlwings的实例详解
开发语言·python
2601_9578838432 分钟前
2026年10月 外星人笔记本维修须知
python·电脑
有想法的py工程师38 分钟前
PostgreSQL【内核】 CBO 优化器的“早停下注”与数学模型失效分析
数据库·postgresql
泡茶喝茶写代码40 分钟前
A股量化数据工程:从 REST 接口到策略信号(第 17 篇):创新高与新低扫描
java·python·股票数据api·股票数据api接口·股票api数据接口·股票量化数据api·股票量化数据接口
VIP_CQCRE1 小时前
用 Ace Data Cloud 接入 OpenAI 兼容语音转文字:一份能直接运行的 API 指南
python·openai·api·语音识别·acedatacloud
冰暮流星1 小时前
sql之计算
数据库·sql
dishugj1 小时前
HANA集群状态监控
数据库·系统架构
小蒜学长2 小时前
基于Java的公司采购系统的设计与实现(代码+数据库+LW)
java·数据库·spring boot·后端·公司采购系统
lee_tianbai2 小时前
Java SSM 电影票预定系统|完整前后端项目,开箱即用(源码分享)
java·开发语言·数据库