python – Django – 设置urls.py和views.py
我是Django的新手,我正在尝试配置我的urls.py和views.py文档.这可能是一个非常简单的问题,但我不能为我的生活设置我的urls.py和views.py文档,以便localhost / index指向我创建的index.html文件.我已经按照Django项目教程来写了这封信并试了很多很多变种,但这并不是为了点击我.任何帮助将非常感激!
index.html文件位于mysite / templates / index.html
我的文件夹结构是这样的……
mysite/
mysite/
__init__.py
settings.py
urls.py
wsgi.py
app/
__init__.py
admin.py
models.py
tests.py
urls.py
views.py
templates/
css
img
js
index.html
我的views.py包含:
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import Context, loader
from django.http import Http404
def index(request):
return render(request, "templates/index.html")
更新:我的文件夹结构现在看起来像这样:
mysite/
mysite/
__init__.py
settings.py
urls.py
wsgi.py
templates/
index.html
app/
__init__.py
admin.py
models.py
tests.py
urls.py
views.py
static/
css
img
js