Кнопка на html странице загружает файл в django и нужно сделать дальнейшее преобразование этого файла. Например файл формата .txt и построить график
Где найти этот файл который я загрузил на web странице и как построить график с данными из этого файла
Файл views.py
def simple_upload(request):
if request.method == 'POST' and request.FILES['myfile']:
myfile = request.FILES['myfile']
fs = FileSystemStorage()
filename = fs.save(myfile.name, myfile)
uploaded_file_url = fs.url(filename)
return render(request, 'events/algorithm_1.html', {
'uploaded_file_url': uploaded_file_url
})
return render(request, 'events/algorithm_1.html')
def model_form_upload(request):
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('home')
else:
form = DocumentForm()
return render(request, 'events/algorithm_1.html', {
'form': form
})
Файл urls.py
urlpatterns = [
path('', views.home, name='home'),
path('algorithm_1', views.algorithm_1, name='algorithm_1'),
path('project', views.project, name='project'),
]
Файл models.py
class Document(models.Model):
description = models.CharField(max_length=255, blank=True)
document = models.FileField(upload_to='documents/')
uploaded_at = models.DateTimeField(auto_now_add=True)
Файл forms.py
class DocumentForm(forms.ModelForm):
class Meta:
model = Document
fields = ('description', 'document', )
файл algorihtm.html
{% extends 'events/base.html' %}
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Algorithm_1</title>
</head>
<body>
{% block content %}
<div class="center">
<div class="container"><h1>Загрузка и обработка pcap файла </h1>
<div class="file">
<div>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile">
<button type="submit">Загрузить</button>
</form>
{% if uploaded_file_url %}
<p>File uploaded at: <a href="{{ uploaded_file_url }}">{{ uploaded_file_url }}</a></p>
{% endif %}
<p><a href="{% url 'algorithm_1' %}">Return to home</a></p>
</div>