Skip to content

Commit

Permalink
Error message when no file is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
tiritibambix committed Jan 12, 2025
1 parent dbca2b5 commit 6741855
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,15 @@ def index():
@app.route('/upload', methods=['POST'])
def upload_file():
"""Handle file uploads."""
if 'file' not in request.files:
flash('Aucun fichier sélectionné', 'error')
return redirect(url_for('index'))

files = request.files.getlist('file')
if not files or all(file.filename == '' for file in files):
return flash_error('No file selected.'), redirect(url_for('index'))

flash('Veuillez sélectionner au moins un fichier', 'error')
return redirect(url_for('index'))

uploaded_files = []
for file in files:
if file and allowed_file(file.filename):
Expand Down
35 changes: 35 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,32 @@
border-color: var(--clr-primary-a40);
}

.flash-messages {
margin-bottom: var(--spacing-medium);
padding: var(--spacing-small);
border-radius: 4px;
width: 100%;
box-sizing: border-box;
}

.flash-message {
padding: var(--spacing-small);
margin-bottom: var(--spacing-small);
border-radius: 4px;
background-color: var(--clr-surface-a20);
color: var(--clr-primary-a50);
}

.flash-message.error {
background-color: #ff4444;
color: white;
}

.flash-message.success {
background-color: #00C851;
color: white;
}

@media (min-width: 768px) {
.container {
max-width: 600px;
Expand All @@ -145,6 +171,15 @@
</head>
<body>
<div class="container">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<div class="flash-messages">
{% for category, message in messages %}
<div class="flash-message {{ category }}">{{ message }}</div>
{% endfor %}
</div>
{% endif %}
{% endwith %}
<form action="/upload" method="post" enctype="multipart/form-data">
<fieldset>
<legend class="title-large">ImaGUIck</legend>
Expand Down

0 comments on commit 6741855

Please sign in to comment.