程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Django logic call

編輯:Python


tests.py

resolve The function is django Functions used internally , For parsing url, And map it to the corresponding view function , When checking the site root path "/", Can I find

home_page function

'''from django.test import TestCase # Create your tests here. class Smokeclass(TestCase): def test_bad_maths(self): self.assertEquals(1+1,3)'''''
from django.urls import resolve
from django.test import TestCase
from lists.views import home_page
class HomePageTest(TestCase):
def test_root_url_resolve_to_home_page_view(self):
found=resolve('/')#resolve The function is django Functions used internally , For parsing url, And map it to the corresponding view function , When checking the site root path "/", Can I find home_page function 
self.assertEquals(found.func,home_page)

urls.py

django use urls File mapping view function

"""superlists URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.10/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """
from django.conf.urls import url
from django.contrib import admin
from lists import views
from django.conf.urls import url
urlpatterns = [
# url(r'^admin/', admin.site.urls),
url(r'^$',views.home_page,name='home'),
]

views.py

from django.shortcuts import render
# Create your views here.
def home_page():
pass


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved