You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
932 B
23 lines
932 B
from django.http import HttpResponseRedirect
|
|
from django.shortcuts import render
|
|
from .apps import DetectAppConfig
|
|
from .forms import UploadFileForm
|
|
from .upload import handle_uploaded_file
|
|
from .detect import detect
|
|
|
|
|
|
def upload_file(request):
|
|
result = None
|
|
if request.method == 'POST':
|
|
form = UploadFileForm(request.POST, request.FILES)
|
|
if form.is_valid():
|
|
input_path = DetectAppConfig.image_filebase + DetectAppConfig.image_file_input
|
|
output_path = DetectAppConfig.image_filebase + DetectAppConfig.image_file_output
|
|
output_url = DetectAppConfig.image_urlbase + DetectAppConfig.image_file_output
|
|
|
|
handle_uploaded_file(request.FILES['file'], input_path)
|
|
detect(input_path, output_path)
|
|
result = output_url
|
|
else:
|
|
form = UploadFileForm()
|
|
return render(request, 'detect_app/upload.html', {'form': form, 'result': result})
|