from django.contrib import admin
from django.urls import path
from learn import views as learn_views
urlpatterns = [path('', learn_views.index),
path('admin/', admin.site.urls)]
python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
July 03, 2018 - 16:39:12
Django version 2.0.4, using settings 'Test.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Hello World!
django-admin.py startproject zqxt_views
cd zqxt_views
python manage.py startapp calc
from django.shortcuts import render
from django.http import HttpResponse
def add(request):
a = request.GET['a']
b = request.GET['b']
c = int(a) + int(b)
return HttpResponse(src(c))
from django.contrib import admin
from django.urls import path
from calc import views as calc_views
urlpatterns = [path('add/', calc_views.add, name='add'),
path('admin/'), admin.site.urls]
python manage.py runserver 8002
Performing system checks...
System check identified no issues (0 silenced).
You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
July 03, 2018 - 17:13:58
Django version 2.0.4, using settings 'zqxt_views.settings'
Starting development server at http://127.0.0.1:8002/
Quit the server with CTRL-BREAK.
def add2(request, a, b):
c = int(a) + int(b)
return HttpResponse(str(c))
path('add/<int:a>/<int:b>/', calc_views.add2, name = 'add2')
from django.conf.urls import url
from django.contrib import admin
from calc import views as calc_views
urlpatterns = [
path('add/<int:a>/<int:b>/', calc_views.add2, name= 'add2'),
path('add/', calc_views.add, name='add'),
path('admin/', admin.site.urls),
]
from django.http import HttpResponse
from django.shortcuts import render
# 部分代码
def index(request):
return render(request, 'home.html')