File size: 3,392 Bytes
87da3f6
dce7a03
 
 
 
b2adfba
dce7a03
 
 
 
87da3f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dce7a03
 
87da3f6
dce7a03
 
 
 
 
 
 
 
b2adfba
dce7a03
 
 
67c58b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from flask import Flask, render_template_string, request, redirect, url_for
import os
from werkzeug.utils import secure_filename

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = '.'  # Используем текущую директорию
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)

stories = []

HTML = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Мобильная Веб-страница Историй</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f8f9fa;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 90%;
            max-width: 600px;
        }
        .story-list {
            display: flex;
            overflow-x: auto;
            padding-bottom: 10px;
            margin-bottom: 20px;
        }
        .story-item {
            flex: 0 0 auto;
            width: 100px;
            height: 100px;
            margin-right: 10px;
            border-radius: 50%;
            overflow: hidden;
            border: 2px solid #007bff;
        }
        .story-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        #addStoryButton {
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Истории</h1>
        <div class="story-list">
            {% for story in stories %}
                <div class="story-item">
                    <img src="{{ story.image }}" alt="История">
                </div>
            {% endfor %}
        </div>
        <form action="/add_story" method="post" enctype="multipart/form-data">
            <div class="form-group">
                <input type="file" class="form-control-file" id="photo" name="photo" accept="image/*">
            </div>
            <button type="submit" class="btn btn-primary" id="addStoryButton">Добавить историю</button>
        </form>
    </div>
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.3/dist/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
"""

@app.route('/')
def index():
    return render_template_string(HTML, stories=stories)

@app.route('/add_story', methods=['POST'])
def add_story():
    if 'photo' in request.files:
        photo = request.files['photo']
        if photo.filename != '':
            filename = secure_filename(photo.filename)
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            stories.insert(0, {'image': filename})  # Сохраняем только имя файла
    return redirect(url_for('index'))

if __name__ == '__main__':
    app.run(debug=True,host="0.0.0.0" , port=7860)