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']
相关推荐
摇滚侠20 分钟前
Spring 零基础入门到进阶 基于 XML 管理 Bean 14-28
xml·数据库·spring
Metaphor69235 分钟前
使用 Python 给 PDF 设置背景色或背景图
数据库·python·pdf
Gauss松鼠会36 分钟前
【GaussDB】GaussDB重要通信参数汇总
服务器·网络·数据库·sql·性能优化·gaussdb·经验总结
睡不醒男孩0308231 小时前
第五篇:2026年企业级 PostgreSQL 高可用方案深度横评:Patroni vs. CLup 架构与可靠性全面对决
数据库·postgresql·架构
NineData1 小时前
SQL 都在等锁时,ChatDBA 先帮 MySQL 找到谁在挡路
数据库·人工智能·sql·mysql·安全·数据复制·数据迁移工具
超级无敌zhq1 小时前
后渗透痕迹清理:攻防对抗中的隐身术
网络·数据库·网络安全
郝亚军1 小时前
如何让pycharm-2026.1.2顶部菜单栏固定显示在最上端
python
怪兽学LLM1 小时前
LeetCode 438 找到字符串中所有字母异位词(Python 固定滑动窗口+字符计数解法)
python·算法·leetcode
麻雀飞吧1 小时前
期货量化日志别泄露密码:天勤账户凭证脱敏写法
python