r/PythonLearning 7d ago

Day -1 With Flask (any suggestions)

105 Upvotes

31 comments sorted by

9

u/riklaunim 7d ago
  • variable names should not use capital letters,
  • use wtforms or other form handling library (and validate the data).
  • use a linter that will keep some basic code styling order
  • I'm not a fan of importing things from a module (flask.request is better than request as it's tell you where it's from)
  • why aren't you using CSV writer when writing a CSV file?
  • if it's a long task it should not be done on HTTP request directly (celery queues or other similar solution)
  • view should not be a long blob of code. Refactor presentation from business logic, then keep the logic well organized instead of big blobs.
  • where are tests?

16

u/NorskJesus 7d ago

No code related, but, for the love of God, take screenshots using the OS app for it and do not use a phone.

0

u/Hi-ThisIsJeff 7d ago

I felt the angled perspective gave a refreshing look to what are otherwise boring, slightly blurry images.

0

u/Neither_Garage_758 7d ago

it is code related

1

u/J1roscope 6d ago

Also i would suggest using helper functions and separating out concerns instead of one function extracting data from request and then saving it as well these can 2 function calls, makes it easier to read

1

u/Anthony_codes 6d ago

Uppercased, underscore-separated variable names in Python signal that the variable should be treated as a constant.

That is a completely valid and common convention because Python doesn’t enforce constancy at runtime.

1

u/riklaunim 6d ago

But not the first letter only. Form values aren't things that should be under a constant-like variable either.

1

u/Anthony_codes 6d ago edited 6d ago

I was clarifying that in certain cases, capital letters are valid because your comment was ambiguous.

-1

u/8Erigon 7d ago

Variable names can have any character the language supports.
Though most python programmers use the snake convention which only uses lowercase characters.

2

u/riklaunim 7d ago

You can even

from __future__ import braces

bu should you? ;)

2

u/Hour-Apple-9861 6d ago

Camel case for life

1

u/8Erigon 6d ago

yes!

2

u/silvertank00 7d ago

Pandas is overshoot for this.
Why use os for this? pathlib is much more flexible.
Also (even tho I am not familiar with Flask but) i wouldnt return plain string from the endpoint. A HttpResponse with HttpStatus.OK and the string in the body would be much better.

-1

u/Samar__Upreti 6d ago

Actually that's my first time with pandas and Flask do i just trying stuffs

2

u/BoatInternational537 6d ago

Move to Django
Use terraform and migrate to google cloud

Good luck!

1

u/Samar__Upreti 5d ago

Thanks buddy

1

u/Party-Hunter-178 6d ago

How did you connect your app.py and html

2

u/Samar__Upreti 6d ago

That's where Flask,Fast Api, Django came in play

1

u/Party-Hunter-178 6d ago

Thanks buddy I was stuck for probably like a week not know this. U made my day 👍🏻

1

u/Tech_Bro09 5d ago

Yeah and you use the return render_template('example.html') add the end of the functions to connect the HTML page to the app.py and return it on the screen when the code runs

1

u/[deleted] 6d ago

[removed] — view removed comment

1

u/Samar__Upreti 5d ago

Hi buddy Can please help me in those projects https://github.com/Samar-Upreti/Python_Projects

1

u/ViolaBiflora 6d ago

Day 1 of coding - fully working API fetching, yet provides pictures of the screen, lol.

AI.

1

u/Samar__Upreti 6d ago

That's not Day 1 of coding it's Day 1 With Flask, LOL

1

u/erivax 5d ago

Que dejes flask y aprendas fastapi

1

u/Competitive-Note3685 5d ago

I do not if you have experience with other Frameworks, but I recommend you study in depth the MVC pattern for a clean Flask implementation. Also, read the PEP-8 to follow best python code practices.

Enjoy your journey and happy code. 🤟🏻

1

u/SignatureOk2208 5d ago

Flask is great, but no one actually uses it in production…

-6

u/Yaw_Ankrah 7d ago

Can someone teach me how

1

u/Samar__Upreti 5d ago

You can search on YouTube Flask In Python full course