From d907467561e9c8d1991510da2520aac49c012132 Mon Sep 17 00:00:00 2001 From: James Turk Date: Wed, 1 Apr 2015 18:19:20 -0400 Subject: [PATCH] basic upload test --- lifting/views.py | 15 ++++++++++++++- templates/upload.html | 5 +++++ web/settings.py | 2 +- web/urls.py | 6 ++---- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 templates/upload.html diff --git a/lifting/views.py b/lifting/views.py index 91ea44a..562a813 100644 --- a/lifting/views.py +++ b/lifting/views.py @@ -1,3 +1,16 @@ from django.shortcuts import render +from django import forms -# Create your views here. + +class FitnotesUploadForm(forms.Form): + file = forms.FileField() + + +def fitnotes_upload(request): + if request.method == 'POST': + form = FitnotesUploadForm(request.POST, request.FILES) + if form.is_valid(): + print(request.FILES['file']) + else: + form = FitnotesUploadForm() + return render(request, 'upload.html', {'form': form}) diff --git a/templates/upload.html b/templates/upload.html new file mode 100644 index 0000000..e0d453c --- /dev/null +++ b/templates/upload.html @@ -0,0 +1,5 @@ +
+{% csrf_token %} +{{form}} + +
diff --git a/web/settings.py b/web/settings.py index 40faf16..7480504 100644 --- a/web/settings.py +++ b/web/settings.py @@ -39,7 +39,7 @@ ROOT_URLCONF = 'web.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': ['templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ diff --git a/web/urls.py b/web/urls.py index 49762b6..e8d1957 100644 --- a/web/urls.py +++ b/web/urls.py @@ -2,9 +2,7 @@ from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ - # Examples: - # url(r'^$', 'web.views.home', name='home'), - # url(r'^blog/', include('blog.urls')), - url(r'^admin/', include(admin.site.urls)), + + url(r'^fitnotes-upload/$', 'lifting.views.fitnotes_upload'), ]