Html. проблема с

Ответы (1 шт):

Автор решения: Victor VosMottor thanks Monica

Если используете cgi, то это файл питона, а не html.(тока сервер надо настроить на питон)

import cgi
import html
import http.cookies
import os

from _wall import Wall
wall = Wall()

user = ''
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
session = cookie.get("session")
pattern = '''
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<p>
    <h3>
    <a href = 'index.py'>Antalk</a>
    <a href = 'wall.py'>Main</a>
    <a href = 'reg.py'>Registration</a>
    <h3>
<p>
<title>Wall</title>
</head>
<body>
     Login and registration form. If you enter a nonexistent name, a new user is registered.
     <form action="/cgi-bin/wall.py">
        Username: <input type="text" name="login">
        Password: <input type="password" name="password">
        <input type="hidden" name="action" value="login">
        <input type="submit" value = "yes">
    </form>

    {posts}

    {publish}
</body>
</html>
'''
if session is not None:
    session = session.value
user = wall.find_cookie(session)
form = cgi.FieldStorage()
action = form.getfirst("action", "")

if action == "publish":
    text = form.getfirst("text", "")
    text = html.escape(text)
    if text and user is not None:
        wall.publish(user, text)
elif action == "login":
    login = form.getfirst("login", "")
    login = html.escape(login)
    password = form.getfirst("password", "")
    password = html.escape(password)
    if wall.find(login, password):
        cookie = wall.set_cookie(login)
        print('Set-cookie: session={}'.format(cookie))
    elif wall.find(login):
        user = None
        pattern = '''
        <!DOCTYPE HTML>
        <html>
        <head>
        <meta charset="utf-8">
        <p>
            <h3>
            <a href = 'index.py'>Antalk</a>
            <a href = 'wall.py'>Main</a>
            <a href = 'reg.py'>Registration</a>
            <h3>
        <p>
        <title>Wall</title>
        </head>
        <body>
            Password isn't right
            <form action="/cgi-bin/wall.py">
                Username: <input type="text" name="login">
                Password: <input type="password" name="password">
                <input type="hidden" name="action" value="login">
                <input type="submit" value  = "yes">
            </form>
            
            {posts}
            {publish}
        </body>
        </html>
        '''
    else:
        wall.register(login, password)
        cookie = wall.set_cookie(login)
        print('Set-cookie: session={}'.format(cookie))


if user is not None:
    pub = '''
    <form action="/cgi-bin/wall.py">
        <textarea name="text"></textarea>
        <input type="hidden" name="action" value="publish">
        <input type="submit" value = "yes">
    </form>
    '''
else:
    pub = ''

print('Content-type: text/html\n'

print(pattern.format(posts=wall.html_list(), publish=pub))
→ Ссылка