· 7 years ago · Apr 16, 2018, 04:58 AM
1from django import forms
2
3class UploadForm(forms.Form):
4 file = forms.FileField()
5
6from django.shortcuts import render
7from .forms import UploadForm
8
9def index(request):
10 if request.method is not 'POST':
11 form = UploadForm()
12 return render(request, 'index.html', {'form': form})
13 else:
14 pass
15
16<!DOCTYPE html>
17<html lang="en">
18<head>
19 <meta charset="UTF-8">
20 <title>Title</title>
21</head>
22<body>
23 <form method="post" enctype="multipart/form-data" novalidate>
24 {% csrf_token %}
25 {% for field in form %}
26 <div class="form-group">
27 {{ field.label_tag }}
28 {{ field }}
29 </div>
30 {% endfor %}
31 <button type="submit">Сохранить</button>
32 </form>
33</body>
34</html>
35
36from django.contrib import admin
37from django.urls import path
38from django.conf.urls.static import static
39from django.conf import settings
40
41
42from django_tus.views import TusUpload
43from index.views import index
44
45urlpatterns = [
46 path('', index, name='index'),
47 path('admin/', admin.site.urls),
48 path('upload/', TusUpload.as_view(), name='tus_upload'),
49 path('upload/(?P<resource_id>[0-9a-z-]+)', TusUpload.as_view(), name='tus_upload_chunks'),
50] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
51
52"""
53
54Generated by 'django-admin startproject' using Django 2.0.1.
55
56For more information on this file, see
57https://docs.djangoproject.com/en/2.0/topics/settings/
58
59For the full list of settings and their values, see
60https://docs.djangoproject.com/en/2.0/ref/settings/
61"""
62
63import os
64
65# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
66BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
67
68
69# Quick-start development settings - unsuitable for production
70# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
71
72# SECURITY WARNING: keep the secret key used in production secret!
73SECRET_KEY = '%_u!4k)%d%)v%i(now!bdy3-fxu*^q9yb))ui2#pb6!7oi2y!)'
74
75# SECURITY WARNING: don't run with debug turned on in production!
76DEBUG = True
77
78ALLOWED_HOSTS = []
79
80
81# Application definition
82
83INSTALLED_APPS = [
84 'django.contrib.admin',
85 'django.contrib.auth',
86 'django.contrib.contenttypes',
87 'django.contrib.sessions',
88 'django.contrib.messages',
89 'django.contrib.staticfiles',
90
91 'index',
92
93 'django_tus',
94]
95
96MIDDLEWARE = [
97 'django.middleware.security.SecurityMiddleware',
98 'django.contrib.sessions.middleware.SessionMiddleware',
99 'django.middleware.common.CommonMiddleware',
100 'django.middleware.csrf.CsrfViewMiddleware',
101 'django.contrib.auth.middleware.AuthenticationMiddleware',
102 'django.contrib.messages.middleware.MessageMiddleware',
103 'django.middleware.clickjacking.XFrameOptionsMiddleware',
104]
105
106ROOT_URLCONF = 'opencv.urls'
107
108TEMPLATES = [
109 {
110 'BACKEND': 'django.template.backends.django.DjangoTemplates',
111 'DIRS': [
112 os.path.join(BASE_DIR, 'templates'),
113 ],
114 'APP_DIRS': True,
115 'OPTIONS': {
116 'context_processors': [
117 'django.template.context_processors.debug',
118 'django.template.context_processors.request',
119 'django.contrib.auth.context_processors.auth',
120 'django.contrib.messages.context_processors.messages',
121 ],
122 },
123 },
124]
125
126WSGI_APPLICATION = 'opencv.wsgi.application'
127
128
129# Database
130# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
131
132DATABASES = {
133 'default': {
134 'ENGINE': 'django.db.backends.sqlite3',
135 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
136 }
137}
138
139
140# Password validation
141# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
142
143AUTH_PASSWORD_VALIDATORS = [
144 {
145 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
146 },
147 {
148 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
149 },
150 {
151 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
152 },
153 {
154 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
155 },
156]
157
158
159# Internationalization
160# https://docs.djangoproject.com/en/2.0/topics/i18n/
161
162LANGUAGE_CODE = 'en-us'
163
164TIME_ZONE = 'UTC'
165
166USE_I18N = True
167
168USE_L10N = True
169
170USE_TZ = True
171
172
173# Static files (CSS, JavaScript, Images)
174# https://docs.djangoproject.com/en/2.0/howto/static-files/
175
176STATIC_URL = '/static/'
177
178MEDIA_ROOT = os.path.join(BASE_DIR, '/upload')
179MEDIA_URL = 'media/'