├── .gitignore ├── README.md └── uploader ├── __init__.py ├── admin.py ├── apps.py ├── migrations ├── 0001_initial.py └── __init__.py ├── models.py ├── templates └── uploader │ └── upload_form.html ├── tests.py ├── urls.py └── views.py /.gitignore: -------------------------------------------------------------------------------- 1 | #upload folder 2 | media/ 3 | db.sqlite3 4 | venv/ 5 | 6 | 7 | # Byte-compiled / optimized / DLL files 8 | __pycache__/ 9 | *.py[cod] 10 | 11 | # C extensions 12 | *.so 13 | 14 | # Distribution / packaging 15 | .Python 16 | env/ 17 | bin/ 18 | build/ 19 | develop-eggs/ 20 | dist/ 21 | eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .cache 40 | nosetests.xml 41 | coverage.xml 42 | 43 | # Translations 44 | *.mo 45 | 46 | # Mr Developer 47 | .mr.developer.cfg 48 | .project 49 | .pydevproject 50 | 51 | # Rope 52 | .ropeproject 53 | 54 | # Django stuff: 55 | *.log 56 | *.pot 57 | 58 | # Sphinx documentation 59 | docs/_build/ 60 | 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # simple django imageupload(django 3.x) 2 | 3 | ## [demo](https://djangofileupload.herokuapp.com/) 4 | 5 | ## usage 6 | 7 | ### 1. Download the folder `uploader`: 8 | 9 | Download the folder `uploader` and save it in your project directory. 10 | 11 | ### 2. Update `setting.py` of your project: 12 | 13 | On `setting.py` add: 14 | 15 | INSTALLED_APPS = [ 16 | 'uploader', 17 | ...... 18 | ] 19 | 20 | MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 21 | MEDIA_URL = '/media/' 22 | 23 | ### 3. Update `urls.py` of your project: 24 | 25 | On `urls.py` add: 26 | 27 | ...... 28 | from django.urls import path,include 29 | 30 | urlpatterns = [ 31 | ...... 32 | path('uploader/', include('uploader.urls')), 33 | ] 34 | 35 | ### 4. Syncronize database 36 | 37 | $ python manage.py migrate 38 | $ python manage.py runserver 39 | 40 | visit 41 | -------------------------------------------------------------------------------- /uploader/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suhailvs/djangofileupload/40b73cdf5c50bd44a4956ec70cf52d4c358f58c2/uploader/__init__.py -------------------------------------------------------------------------------- /uploader/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /uploader/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class UploaderConfig(AppConfig): 5 | name = 'uploader' 6 | -------------------------------------------------------------------------------- /uploader/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.5 on 2020-04-20 15:29 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Upload', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('upload_file', models.FileField(upload_to='')), 19 | ('upload_date', models.DateTimeField(auto_now_add=True)), 20 | ], 21 | ), 22 | ] 23 | -------------------------------------------------------------------------------- /uploader/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suhailvs/djangofileupload/40b73cdf5c50bd44a4956ec70cf52d4c358f58c2/uploader/migrations/__init__.py -------------------------------------------------------------------------------- /uploader/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | class Upload(models.Model): 4 | upload_file = models.FileField() 5 | upload_date = models.DateTimeField(auto_now_add =True) -------------------------------------------------------------------------------- /uploader/templates/uploader/upload_form.html: -------------------------------------------------------------------------------- 1 |
2 |

Django File Upload

3 |
4 | {% csrf_token %} 5 | {{ form.as_p }} 6 | 7 |

8 |
    9 | {% for document in documents %} 10 |
  • 11 | {{ document.upload_file.name }} 12 | ({{ document.upload_file.size|filesizeformat }}) - {{document.upload_date}} 13 |
  • 14 | {% endfor %} 15 |
16 |
-------------------------------------------------------------------------------- /uploader/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /uploader/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from django.conf import settings 3 | from django.conf.urls.static import static 4 | from . import views 5 | 6 | urlpatterns = [ 7 | path('', views.UploadView.as_view(), name='fileupload'), 8 | ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) -------------------------------------------------------------------------------- /uploader/views.py: -------------------------------------------------------------------------------- 1 | from django.views.generic.edit import CreateView 2 | from django.urls import reverse_lazy 3 | 4 | from .models import Upload 5 | 6 | class UploadView(CreateView): 7 | model = Upload 8 | fields = ['upload_file', ] 9 | success_url = reverse_lazy('fileupload') 10 | 11 | def get_context_data(self, **kwargs): 12 | context = super().get_context_data(**kwargs) 13 | context['documents'] = Upload.objects.all() 14 | return context --------------------------------------------------------------------------------