0
1試圖使用Django 1.10來創建文件上傳系統(類似於這個例子here。我的主要問題是,不管我多麼努力,Django無法顯示我的網頁(404錯誤)我不知道爲什麼,我在下面的例子1.9,它應該是工作,據我可以告訴。我已經附加了錯誤,我的數據樹Django無法顯示網頁
[D:.
│ db.sqlite3
│ manage.py
│
├───.idea
│ courseworkupload.iml
│ misc.xml
│ modules.xml
│ workspace.xml
│
├───courseworkupload
│ │ settings.py
│ │ urls.py
│ │ wsgi.py
│ │ __init__.py
│ │
│ └───__pycache__
│ settings.cpython-35.pyc
│ urls.cpython-35.pyc
│ wsgi.cpython-35.pyc
│ __init__.cpython-35.pyc
│
├───upload
│ │ admin.py
│ │ apps.py
│ │ forms.py
│ │ models.py
│ │ tests.py
│ │ urls.py
│ │ views.py
│ │ __init__.py
│ │
│ ├───migrations
│ │ │ 0001_initial.py
│ │ │ __init__.py
│ │ │
│ │ └───__pycache__
│ │ 0001_initial.cpython-35.pyc
│ │ __init__.cpython-35.pyc
│ │
│ ├───templates
│ │ Final.html
│ │ upload.html
│ │
│ ├───uploadedfiles
│ └───__pycache__
│ admin.cpython-35.pyc
│ forms.cpython-35.pyc
│ models.cpython-35.pyc
│ urls.cpython-35.pyc
│ views.cpython-35.pyc
│ __init__.cpython-35.pyc
│
├───Uploadedfiles
└───__pycache__
manage.cpython-35.pyc][2]
下面的Views.py
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.shortcuts import render
from django.core.urlresolvers import reverse
from .forms import docfieldform
from .models import Document
def upload(request):
if request.method == 'POST':
form = docfieldForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document (docfile=request.FILES['newfile'])
newdoc.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('upload'))
else:
form = docfieldform()
return render(request,'Final.html',)
鏈接圖像https://i.stack.imgur.com/4gIzy.png – 102254563
在您的網址,你錯過了'.html'部分。應該是'http://127.0.0.1:8000/upload/upload.html /' –
@evansmurthi,您好,您嘗試過更改仍然沒有運氣。 – 102254563