Skip to content

add title= kwarg to fast_app() constructor #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025

Conversation

mmacpherson
Copy link
Contributor


name: Pull Request
about: Propose changes to the codebase
title: '[PR] allow default title to be set from fast_app()'
labels: ''
assignees: ''


Related Issue
Please link to the issue that this pull request addresses. If there isn't one, please create an issue first.

#485
(#604)

Proposed Changes

This PR would add a title= kwarg to the fast_app() constructor, and have the effect of allowing a default page title to be set. It needn't do very much, because the underlying functionality was added to FastHTML() in #604 ; this PR just connects them.

Types of changes
What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist
Go over all the following points, and put an x in all the boxes that apply:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • [x + NOTE] I am aware that this is an nbdev project, and I have edited, cleaned, and synced the source notebooks instead of editing .py or .md files directly.

Additional Information

  • I confirmed that this works, by adding a title='hello' to the example from the docs here: https://www.fastht.ml/docs/#usage
  • By declaring as title:str="FastHTML page" I have repeated that default from FastHTML(). This seemed simpler/less intrusive than declaring title:Optional[str]=None, and handling it downstream to avoid the DRY.
  • AFAICT there are no docs or tests that would need to be updated for this.
  • This fast_app call appears to exist outside the nbdev subset, and so if I'm not mistaken there it is appropriate to edit the python code in place.

@jph00 jph00 added the enhancement New feature or request label May 29, 2025
@jph00
Copy link
Contributor

jph00 commented May 29, 2025

Thank you! :)

@jph00 jph00 merged commit 96ea074 into AnswerDotAI:main May 29, 2025
1 check passed
@jmsanchez-ibiza
Copy link

For the title I use the following code:

Define the headers of the app

hdrs = [
bootstrap_css,
bootstrap_js,
Script(src='https://cdn.jsdelivr.net/npm/sweetalert2@11'),
Link(rel="icon", type="image/x-ico", href="img/icon.png"),
Link(rel='stylesheet', href='css/styles.css', type='text/css'),
Link(rel='stylesheet', href='css/modales.css', type='text/css'),
Script(src="js/main.js"),
Script(code="function cambiarTema(tema) {document.documentElement.setAttribute('data-theme', tema);}"),
Script(src="https://unpkg.com/lucide@lastest"),
Script(code=f"document.title='{APP_NOMBRE}';"),
bootstrap_icons,
scroll_to_id_js(),
]

Create the app

app, rt = fast_app(
live=LIVE,
debug=DEBUG,
port=PORT,
pico=False,
static_path="static",
hdrs=hdrs,
htmlkw={"lang":"es", "data-theme":"light"}, # Pasamos estos parámetros al
)

This way I can set the title and also the ‘lang’ which in my case is in Spanish.

Greetings and thank you very much for this great software.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants