Django 加载 app 中的urls
在 blog app 下创建 urls.py, 定义该 app 下自有的 url : new/story
from blog import views
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import url, include
urlpatterns = [
url(r'new/story', views.introduce),
]+ static(settings.STATIC_URL, document_root=settings.STATICFILES_DIRS)
在 blog app views.py 下创建简单的函数 introduce
def introduce(req):
return HttpResponse("Hello world")
在 mysit 项目下的 urls.py 中加载 blog app 下创建 urls.py
from django.conf.urls import url, include
urlpatterns = [
path('admin/', admin.site.urls),
url(r'blog/', include('blog.urls')),
]+ static(settings.STATIC_URL, document_root=settings.STATICFILES_DIRS)