开发实践0_project

要求:oneapp后据参数返回两种页面,无参返回某页面。

一、httpresponse

1. new project: dev0_pro

2. pip install django

3. //setting.py

DEBUG = False
ALLOWED_HOSTS = ["*"]

4. //oneapp views

from django.http import HttpResponse


def whaaat(request, para = None):
    if not para:
        return HttpResponse("

哦哟。不得行。

") elif para == "sentence": return HttpResponse("

无逾我墙,无折我树桑。

") elif para == "tracing": return HttpResponse("

将仲子·先秦·佚名

") else: return HttpResponse("

朔宁夫 开发课

")

5. //oneapp urls.py

from django.urls import path
from oneapp.views import whaaat

urlpatterns = [
    path("whaaat//", whaaat),
    path("whaaat/", whaaat),
]

6. // 总路由

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('oneapp/',  include('oneapp.urls')),
]

二、render

4. 写对应的html模板




    
    你好。江湖再见。


你传入的参数是:Nothing

我是谁我在哪我干啥呢

5. oneapp/views.py

from django.shortcuts import render
def wwwhat(request, param = None):
    if not param:
        return render(request, "nonePara.html")
    elif param == "sentence":
        return render(request, "sentencePara.html")
    elif param == "tracing":
        return render(request, "tracingPara.html")
    else:
        return render(request, "elsePara.html")

6.oneapp urls

from django.urls import path
from oneapp.views import whaaat, wwwhat

urlpatterns = [
    path("whaaat//", whaaat),
    path("whaaat/", whaaat),
    path("wwwhat//", wwwhat),
    path("wwwhat/", wwwhat),
]

7. total route

不用改。

你可能感兴趣的:(pycharm,django)