django 入门小程序

由于博客内容为空,无法提供包含关键信息的摘要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1.django-admin startproject pro1 创建目录
 2.
 cd pro1  移动到目录
 python3 manage.py startapp hello 创建应用
 3.
 vi pro1/settings.py
 把应用的名字 (hello) 添加到 INSTALLED_APPS 列表中
         INSTALLED_APPS = [
            'hello',
            'django.contrib.admin',
            'django.contrib.auth',
            ...
        ]
 4.
  vi pro1/urls.py

            from django.conf.urls import url, include
            # from app1.views import hello


            url(r'^hello/', include('hello.urls'))
   凡是hello/开头的都去到hello下的URL下面找


   5.
vi hello/urls.py
            from django.conf.urls import url
            from .views import morning, afternoon, evening

            urlpatterns = [
                url(r'^morning/', morning),  #以morning为头的调到morning函数
                url(r'^afternoon/', afternoon),
                url(r'^evening/', evening),
            ]
 去到hello下面的urls.py下设置路径


6.
 vi hello/views.py
            from django.shortcuts import render
            from django.http import HttpResponse

            def morning(request):
                return HttpResponse("Good morning")

            def afternoon(request):
                return HttpResponse("Good afternoon")

            def evening(request):
                return HttpResponse("Good evening")

去到hello目录下的views下创建方法

7.

  Python3  manage.py runserver  127.0.0.18000 运行环境(随意设置)

        http://127.0.0.1:8000/hello/morning/
        http://127.0.0.1:8000/hello/afternoon/
        http://127.0.0.1:8000/hello/evening/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值