Reputation: 77
1Trying to use Django 1.10 to create a file upload system (similar to this example here. My main problem is, no matter how hard I try, Django is unable to show my webpage (404 error). I have no idea why. I'm following the 1.9 example and it should be working, as far as I can tell. I've attached the error and my data tree
[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 below
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',)
Upvotes: 0
Views: 62
Reputation: 3257
You need to remove the .html
in your URL conf so that it becomes url(r'^upload/$', upload, name='upload')
. So if your browser url is http://127.0.0.1:8000/upload/upload/
it should go to the upload
view.
To display content in upload.html
replace render(request, 'Final.html')
with render(request, 'upload.html')
in your upload view
Upvotes: 1