#๐Ÿ”’ Flask

175 messages ยท Page 1 of 1 (latest)

weary sparrow
#

My other post got locked or something, but I finished the first steps like pip install flask, and then the code thingy for python, like debugger mode on and all, and I found those flasks file, what should I do now?

twilit scrollBOT
#

@weary sparrow

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

weary sparrow
#

Should I open them, or?

#

Is there something else I should do to activate the flask

#

@spice sleet Need a help, sorry to bother

vital trout
#

Create a Basic Flask Application

grand umbra
#

Everything inside __pycache__ subdirectories has been made by Python as it loads modules. Ignore them - they're cached compiled bytecode of the associated module so that Python doesn't need to compile it a second time unless the source file changes.

vital trout
#

Heres the code

#

from flask import Flask

app = Flask(name)

@app.route('/')
def home():
return 'Hello, World!'

if name == 'main':
app.run(debug=True)

twilit scrollBOT
#

Hey @vital trout!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
vital trout
#

And run it

#

Open a web browser and go to http://127.0.0.1:5000/. You should see the message "Hello, World!" displayed on the page. This confirms that your Flask application is working.

vital trout
#

Yes

#

Name it

weary sparrow
#

Alright let me try

vital trout
#

I'm wrong sorry

weary sparrow
#

Dw

vital trout
#

Its all good

#

Flask is installed

weary sparrow
#

Okay, then how do I like start using it?

#

Like..Insert it into python

vital trout
#

Create a Flask Application

#

Like this one

#

from flask import Flask

app = Flask(name)

@app.route('/')
def home():
return "Hello, World!"

if name == 'main':
app.run(debug=True)

twilit scrollBOT
#

Hey @vital trout!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
vital trout
#

basic code

weary sparrow
#

I have to run the code again?

vital trout
#

No

#

Like these are the steps

#

You need to have your Flask file

weary sparrow
#

I certainly do

#

Yeah I have it

vital trout
#

Then run it to see if theres no problem

#

And then

#

Organize your project

#

For exemple

weary sparrow
#

Like ran the code and closed python

vital trout
#

And in the init.py you need to instert your flask file

#

Heres an example

#

from flask import Flask

def create_app():
app = Flask(name)

with app.app_context():
    # Import parts of our application
    from . import routes
    
    # Register Blueprints, etc.
    
return app
vital trout
#

And tell me what you see

weary sparrow
vital trout
#

Mmh

#

Start the Flask file

weary sparrow
#

The python one, right?

#

Still the same

#

I can't read, because it's closing fast

#

But I did see the word "Error"

#

Wait there's two files

#

"Flask File"

#

"Flask"

vital trout
#

Delete Flask File

weary sparrow
#

Done

vital trout
#

Open "Flask"

weary sparrow
#

It opened and closed, but didn't seem that it ran the code

vital trout
#

Try to make a new one

#

With the same code

weary sparrow
#

Alright

#

That's weird

#

It ran the code and closed

#

I saw "Traceback"

#

When it opened

vital trout
#

Oh

#

I know why that dosen't work

#

You need to call the file

weary sparrow
#

That's what I did tho?

vital trout
#

So when you open it it instanly close ?

weary sparrow
#

Yeah, it shows some codings "Traceback" Or whatever that was

#

And closes

vital trout
#

So

#

When you go to the py app

#

And that open and then close ?

weary sparrow
#

Yes, saved it as app.py and opened it, it closes

vital trout
#

Try this script

#

`from flask import Flask

app = Flask(name)

@app.route('/')
def index():
return 'Hello, Flask!'

if name == 'main':
app.run()
`

weary sparrow
#

Still the same

vital trout
#

Try this command

#

pip show Flask

weary sparrow
vital trout
#

Flask is good

#

But

#

I don't know why you have this error

weary sparrow
#

Do you think it's a lag??

#

I don't know, maybe it's a glitch or something

#

@vital trout It's working

vital trout
#

Like

weary sparrow
vital trout
#

Randomly working ?

#

So

weary sparrow
#

I deleted the file and re-coded

vital trout
#

And in the init.py you need to instert your flask file
Heres an example
from flask import Flask

def createapp():
app = Flask(_name)

with app.app_context():
    # Import parts of our application
    from . import routes

Register Blueprints, etc.
return app

#

So

#

Its like that you put your Flask File in your Python Project

weary sparrow
#

In python?

#

Like new python files?

vital trout
#

Ill send you pictures you will understand

weary sparrow
#

Alright thank you

vital trout
#

so this is my project

weary sparrow
#

Ohh, lemme go try real quick

vital trout
#

and now

#

with this

#

i added Flask into my python project

weary sparrow
#

Like I should create a new folder?

weary sparrow
vital trout
weary sparrow
#

Aight created a new folder

weary sparrow
#

Like..I'm suppose to code them?

vital trout
#

Yeah but i can send you the codes

weary sparrow
#

Yeah please

vital trout
#

Try this config first

rich sundial
vital trout
rich sundial
weary sparrow
#

Huh

rich sundial
#

And have you installed flask, pip install flask

vital trout
#

everything is done

weary sparrow
#

I did all that, I just have to organise the project

vital trout
#

he need to know how to add flask in a python project

rich sundial
#

Have you got your website working?

vital trout
#

yeah

#

the website is working

#

everything is working

weary sparrow
rich sundial
#

Oh

vital trout
#

Everything is working as i said

#

I just took a ChatGPT config to show him how to add flask into a python project

twilit scrollBOT
#

10. Do not copy and paste answers from ChatGPT or similar AI tools.

vital trout
#

My bad

#

i'm new to this server

weary sparrow
#

Uh

#

I'm kinda new to python so I don't know how to code those that much

#

@rich sundial I think I organized my project now, uhm how am I supposed to run it now?

weary sparrow
#

Uh

rich sundial
#

The organization thing was not nessacary

vital trout
placid parcel
rich sundial
weary sparrow
#

I think I coded the run.py wrong

#

Not sure though

#

@vital trout What was the coding for run.py?

buoyant anvil
#

@weary sparrow in case this person sends any files in DMs, you shouldn't download them, it might be a virus.

weary sparrow
#

Yeah of course

#

I'm using a vpn in case it was a tracker too

rich sundial
weary sparrow
#

No, they didn't send anything yet

rich sundial
weary sparrow
#

Uh the "from import" thingy

#

Should I change something?

#

from app import create_app

#

Like here

#

@rich sundial

weary sparrow
#

@buoyant anvil

oak elbow
weary sparrow
#

Ohh

twilit scrollBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.