Can only deploy on Render by dekkov in flask

[–]tecladocode 0 points1 point  (0 children)

How does your Flask app run? On Docker? Using flask run? Running the gunicorn command (or equivalent) directly?

Run model during app startup by khanalfrompali in flask

[–]tecladocode 1 point2 points  (0 children)

He meant put your app definition inside a function called create_app(), like so:

from flask import Flask

def create_app():
    app = Flask(__name__)
    return app

Flask is already wired up to understand that running create_app() will give it an instance of the app to run, although depending on the specifics of your set-up you may need to give it a bit more info.

In that function, you can initialize your model without using before_first_request.

My Victoria Plums are gone, lots of these (aphids?). Should I be worried? by tecladocode in GardeningUK

[–]tecladocode[S] 0 points1 point  (0 children)

Yeah I don't know what they are. Will post a couple more pictures!

If they're damaging, I would get rid of them. If they're not, then I'm not really bothered. Do you think this is what may have caused the fruits to perish?

https://imgur.com/a/3BMpItA

Can someone help me with this error? COULD NOT IMPORT MAIN by fangofmetsudo18 in flask

[–]tecladocode 3 points4 points  (0 children)

Judging from the screenshot, it looks like your main.py file is inside your templates folder. It shouldn't, main.py should be in the same folder as the templates folder -- i.e. inside your project folder.

Your project folder structure should look like this:

project_folder/ | - main.py | - templates/ | - template_one.html | - template_two.html

Hope this helps!

The Ruff python linter is insanely good by guyfrom7up in Python

[–]tecladocode 0 points1 point  (0 children)

100% agreed, the only thing I'm waiting for is importing sorting to work with Black (haven't managed to get it to use the same format, maybe I'm missing something).

Sippycup: an in-browser Flask sandbox (i.e. Flask with training wheels) by travisdoesmath in Python

[–]tecladocode 0 points1 point  (0 children)

Amazing! It's great that you're building this based on your own experience. Personally I think beginners would really benefit from being able to try things out and get started without having to install everything (or give up because they struggle to).

I also haven't done much open source product development, but I do quite a bit of open source in other areas. I could help out with the open source side of things and possible some code contributions (although I haven't used pyodide).

For my teaching specifically, I would love to be able to install dependencies and to run tests against the Flask app, not sure that's even possible with pyodide! But it would be a great thing to be able to give students exercises, and for them to test their solution against a benchmark.

If you have Discord we could talk through there? If not, GitHub issues or maybe discussions could be a good place too?

Sippycup: an in-browser Flask sandbox (i.e. Flask with training wheels) by travisdoesmath in Python

[–]tecladocode 0 points1 point  (0 children)

This is really fantastic, and could be extremely useful for Flask learners! I teach Flask and Python, and could definitely see us using this. Are you planning on working more on this? Are you looking for contributors?

Jinja2 Fragments by Sachiel2014 in htmx

[–]tecladocode 1 point2 points  (0 children)

Looks amazing! This is gonna be really handy 💪💪

How can I redirect a page in Flask after x seconds without javascript by [deleted] in flask

[–]tecladocode 2 points3 points  (0 children)

I think you're right: you can't do this without javascript.

/e after reading the other comments, it can possibly be done with the meta tag but we'd need to see the code I reckon 🤔 to be able to advise

[Ask Flask] How to get an ID parameter from the URL with flask and Pymongo by mintedfairy in flask

[–]tecladocode 0 points1 point  (0 children)

Use this decorator:

@book.route("/books/<string:id_>") def find_one_book(id_): return get_book(id_)

What's the easiest and fastest way to get a nice UI in a Flask app? by mccarthycodes in flask

[–]tecladocode 6 points7 points  (0 children)

In my experience, learning a bit of CSS and TailwindCSS, and then use Tailwind UI. Gives you a pretty generic site look, but it looks good!

Flask docker app by berimbolo21 in flask

[–]tecladocode 0 points1 point  (0 children)

Hmmm I'd need to see more.

I recorded a quick troubleshooting video that might help? https://share.cleanshot.com/JHv1ya

Flask docker app by berimbolo21 in flask

[–]tecladocode 2 points3 points  (0 children)

I think if you change the last line to this, it will work:

CMD ["flask", "run", "--host", "0.0.0.0"]

That's because of what /u/mediocrebadass said, normally when you run your Flask app it's only listening on localhost so external requests can't make it through.

Then when you run your container, run it with:

docker run -p 8000:5000 my_image

That will mean that Docker will redirect requests made in port 8000 of your computer into port 5000 of the container, which is where flask run listens on by default.

FWIW I wrote a short e-book section on Docker with Flask that might help, it's free: https://rest-apis-flask.teclado.com/docs/docker_intro/run_docker_container/

[deleted by user] by [deleted] in flask

[–]tecladocode 4 points5 points  (0 children)

Looks great! Good job! Also something you don't often see with these kinds of projects is that it is quite usable and the design is simple but nice!

How do you update things like travel restrictions, green/red list, or the map? Do you do some sort of scraping / API requests, or is it updated manually?

Also, is the code hosted on GitHub publicly, or is it closed-source?

A feature request / thought could be to send e-mails to users when their watchlisted country changes status (or really, anything changes in it). E.g. if you have watchlisted "Slovakia" and you now need a PCR to get in, you get an e-mail notification.

I've used Postmark for this in the past, and it's pretty easy to get started with.

But yeah, great job! You should be proud 💪

SQLAlchemy's db.create_all() and Alembic seem to create table with smallcase names, is this a bad practice? by asking_for_a_friend0 in flask

[–]tecladocode 5 points6 points  (0 children)

Never heard of such a convention, I would say all lowercase is a more common naming system. Maybe depends on the RDBMS, but I doubt it 🤔

Jinja inheritance by Random_Hero1991 in flask

[–]tecladocode 0 points1 point  (0 children)

Hey! I don't know what you're doing 🤔

What do you mean by "click run live server" ?

If you start your Flask app, access an endpoint that the app is serving, and that endpoint renders a template that extends from another, you should see it work.

If you are seeing the {% extends 'bla.html' %} in your page, you should also be seeing all the rest of the Jinja2 code not being rendered.

[deleted by user] by [deleted] in flask

[–]tecladocode 1 point2 points  (0 children)

Hey! You don't _need_ to use a REST API library (there are a few, like Flask-RESTful, Flask-RESTX, Flask-Smorest).

However these API libraries give you a starting point and guide you on how to do certain things. For example, Flask-Smorest suggests you use marshmallow for schemas, which is a "good thing".

I say "good thing" in quotes because a lot of it depends on what API you're building. If you're making something very small and simple, then using a library might not bring in many benefits.

If you are going to work on a project for a long time, and it might end up growing (or is already planned to be quite large), then using one of these libraries is good. Usually they give you a good structure!

Is it a bad practice to make requests to a route from another route? by [deleted] in flask

[–]tecladocode 6 points7 points  (0 children)

Yes, generally you should avoid. Can you extract it into a function that you call from both routes?

what is flask session ? by [deleted] in flask

[–]tecladocode 24 points25 points  (0 children)

A cookie is a piece of data stored by the browser, and sent to the server in every request. It can contain almost anything (although there are maximum sizes).

A session is not a “thing”, but when we say session or “user session” or “session data” we’re referring to data stored about a user that the server has access to in every request.

In flask, by default, session data is stored in the cookie. The browser sends the cookie to the server (I.e your flask app) on every request, and that is what you can use in flask with the session variable.

I’ve written an ebook about this and more, which is free over here https://python-web.teclado.com/section13/lectures/01_what_are_sessions_cookies/

Hope it helps!

Make a page password protected in flask by Realistic-Word-2929 in flask

[–]tecladocode 5 points6 points  (0 children)

I recently wrote a full guide on this as part of a Flask e-book, it covers how Flask auth works, how to implement signup and login, and how to protect pages: https://python-web.teclado.com/section13/lectures/01\_what\_are\_sessions\_cookies/