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']
相关推荐
一只fish几秒前
Oracle官方文档翻译《Database Concepts 26ai》附录-术语表
数据库·oracle
逗逗班学Python2 分钟前
基于 Faster-Whisper 的本地语音转字幕与会议纪要系统:从音频转写到 SRT 字幕与 Markdown 纪要完整项目实战
python·语音识别·faster-whisper·字幕生成·会议纪要
The moon forgets3 分钟前
ABot-M0:基于动作流形学习的机器人操作VLA基础模型深度解析
人工智能·pytorch·python·学习·具身智能·vla·点云分割
一只fish31 分钟前
Oracle官方文档翻译《Database Concepts 26ai》第23章-数据库开发者概念
数据库·oracle
Cloud_Shy61832 分钟前
解读《Effective Python 3rd Edition》:从练气到老魔(第四章 Item 27 - 29)
开发语言·人工智能·经验分享·python·学习方法
todoitbo34 分钟前
从 MySQL 到 KingbaseES:Database、Schema、User 一次讲透
数据库·mysql·国产数据库·kingbasees
机汇五金_38 分钟前
交换机箱体材质如何选择?铝合金与钢板有什么区别?
python·材质
asdzx6739 分钟前
使用 Python 精准提取 Word 文档中的文本与表格
python·word
某林21241 分钟前
ROS 2 与大模型融合实战:从进程连环崩溃到类型安全防御的深度排障复盘
c++·python·安全·机器人·人机交互·ros2
勇往直前plus1 小时前
Redis&Python 梳理
数据库·redis·python