Django path: 'host:8000/' 临时网页

本文介绍如何使用Django和lambda表达式快速创建一个临时网页,响应网站根路径的请求,展示'MYSITE欢迎页面'。同时,文章分享了Django项目的文件结构,包括mysite项目的创建和app的开发。

Django path: ‘host:8000/’ 临时网页

使用 lambda 一行代码实现临时响应 ‘http://localhost:8000’ 网站根路径的请求。

代码:

#### filename: mysite/mysite/urls.py
[...]
from django.http import HttpResponse

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', lambda request: HttpResponse('Welcome to MYSITE')),

    path("yourApp/", include("yourApp.urls")),

    [...]

简单说明:
mysite 是指: develop/ $ django-admin startproject mysite
yourApp 是指开发的 app: develop/mysite/ $ python3 manage.py startapp yourApp
因此文件结构为:

develop/
    `-- mysite/
           |-- mysite/
           |       |-- urls.py 
           |       |-- settings.py
           |       |-- [...]
           |
           |-- yourApp/
           |       |-- [...]
           |
           |-- manage.py
           |-- db.sqlite3
    [...]

其中,本文所有 [...] 表示“省略”

D:\zhuangmian\project>pip install Django -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com Looking in indexes: http://pypi.douban.com/simple/ WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))': /simple/django/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))': /simple/django/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))': /simple/django/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))': /simple/django/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))': /simple/django/ ERROR: Could not find a version that satisfies the requirement Django (from versions: none) ERROR: No matching distribution found for Django WARNING: You are using pip version 20.1.1; however, version 25.0.1 is available. You should consider upgrading via the 'f:\python3.8\python.exe -m pip install --upgrade pip' command.
04-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值