Я пытаюсь создать обратный вызов для отправки URL-адреса, использованного пользователем, когда он достиг страницы 404. Для других страниц я обычно слушаю сам URL-адрес и инициирую что-то, когда он соответствует шаблону имени пути, но в конкретном случае со страницей 404 это не может работать, поскольку страница не указывает на что-то конкретное.
Вы можете попробовать следующую страницу:
"""Code to generate the layout of a 404 error page."""
import logging
import dash
from dash import Input, Output, State, callback, html
from .. import telemetry
def layout() -> html.Div:
"""Return the layout of a 404 error page."""
# prepare the text in advance to avoid long lines
oops = "Oops! The page you are looking for does not exist."
btn = "Go Back to Main"
# create the different elements of the page
title = html.H1("404")
subtitle = html.H2("Page Not Found")
message = html.P(oops)
button = html.A(btn, href="/")
# add a telemetry tracker
tracker = html.Div(id="not_found_404_tracker", style={"display": "none"})
# create the layout of the 404 page
return html.Div([title, subtitle, message, button])
@callback(
Output("not_found_404_tracker", "children"),
# I guess it's not the right Input and should be a state instead
# and then the real question begin: how to catch when the 404 is reached
Input("url", "pathname"),
State("magic_session", "data"),
prevent_initial_call=False,
)
def track_not_found_404_visit(url, session_data):
"""Track 404 page visit with session ID."""
if session_data and session_data.get("session_id"):
telemetry.add_page_visit(
session_data["session_id"],
"not_found_404_page",
"url": url
)
return ""
dash.register_page(__name__, layout=layout)
Подробнее здесь: https://stackoverflow.com/questions/798 ... -triggered
Как создать обратный вызов при запуске страницы 404? ⇐ Python
Программы на Python
-
Anonymous
1768400809
Anonymous
Я пытаюсь создать обратный вызов для отправки URL-адреса, использованного пользователем, когда он достиг страницы 404. Для других страниц я обычно слушаю сам URL-адрес и инициирую что-то, когда он соответствует шаблону имени пути, но в конкретном случае со страницей 404 это не может работать, поскольку страница не указывает на что-то конкретное.
Вы можете попробовать следующую страницу:
"""Code to generate the layout of a 404 error page."""
import logging
import dash
from dash import Input, Output, State, callback, html
from .. import telemetry
def layout() -> html.Div:
"""Return the layout of a 404 error page."""
# prepare the text in advance to avoid long lines
oops = "Oops! The page you are looking for does not exist."
btn = "Go Back to Main"
# create the different elements of the page
title = html.H1("404")
subtitle = html.H2("Page Not Found")
message = html.P(oops)
button = html.A(btn, href="/")
# add a telemetry tracker
tracker = html.Div(id="not_found_404_tracker", style={"display": "none"})
# create the layout of the 404 page
return html.Div([title, subtitle, message, button])
@callback(
Output("not_found_404_tracker", "children"),
# I guess it's not the right Input and should be a state instead
# and then the real question begin: how to catch when the 404 is reached
Input("url", "pathname"),
State("magic_session", "data"),
prevent_initial_call=False,
)
def track_not_found_404_visit(url, session_data):
"""Track 404 page visit with session ID."""
if session_data and session_data.get("session_id"):
telemetry.add_page_visit(
session_data["session_id"],
"not_found_404_page",
"url": url
)
return ""
dash.register_page(__name__, layout=layout)
Подробнее здесь: [url]https://stackoverflow.com/questions/79867801/how-to-create-a-calback-when-the-404-page-is-triggered[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия