before send to remote
This commit is contained in:
0
upload/__init__.py
Normal file
0
upload/__init__.py
Normal file
3
upload/admin.py
Normal file
3
upload/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
upload/apps.py
Normal file
6
upload/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UploadConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'upload'
|
0
upload/migrations/__init__.py
Normal file
0
upload/migrations/__init__.py
Normal file
3
upload/models.py
Normal file
3
upload/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
13
upload/templates/upload.html
Normal file
13
upload/templates/upload.html
Normal file
@@ -0,0 +1,13 @@
|
||||
{% block content %}
|
||||
|
||||
<form action="{% url 'upload:upload' %}" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<input type="file" name="image_file">
|
||||
<input type="submit" value="submit" />
|
||||
</form>
|
||||
|
||||
{% if image_url %}
|
||||
<p>File uploaded at: <a href="{{ image_url }}">{{ image_url }}</a></p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
3
upload/tests.py
Normal file
3
upload/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
11
upload/urls.py
Normal file
11
upload/urls.py
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
app_name = 'upload'
|
||||
|
||||
urlpatterns = [
|
||||
# ex: /upload/
|
||||
path('', views.upload, name='upload'),
|
||||
]
|
15
upload/views.py
Normal file
15
upload/views.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.shortcuts import render
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
|
||||
|
||||
def upload(request):
|
||||
if request.method == "POST" and request.FILES["image_file"]:
|
||||
image_file = request.FILES["image_file"]
|
||||
fs = FileSystemStorage()
|
||||
filename = fs.save(image_file.name, image_file)
|
||||
image_url = fs.url(filename)
|
||||
print(image_url)
|
||||
return render(request, "upload.html", {
|
||||
"image_url": image_url
|
||||
})
|
||||
return render(request, "upload.html")
|
Reference in New Issue
Block a user