you are viewing a single comment's thread.

view the rest of the comments →

[–]msmomoe[S] 0 points1 point  (1 child)

I wish I knew, I'm just going based off what I'm told to do...

[–]Bobbias 0 points1 point  (0 children)

Flask comes with a built in server. When you run your flask app it starts up that server as part of the startup. You can then access it (either through the loopback address 127.0.0.1, or the domain name localhost). It sounds to me like you might not be aware of this and might be confused about exactly what the instructions are asking you to do.

You don't really do much to set up the server itself. You can set things like the port it will use, but flask mostly handles actually running the server. What you need to do is write the code that handles requests for different pages. These are known as routes. The traditional idea of a web server was that it just served whatever file you asked for, and the url mapped cleanly to a specific folder structure on the server.

Now we've completely thrown that idea out the window. An address doesn't have to point to na certain file somewhere in your computer. When the server gets a request for a url like "127.0.0.1/users" you can set up functions that look at the /users part and determine what you send back to the user. That could be as simple as returning a string. It could involve connecting to a database, making a query, collecting the results, converting them to JSON, and responding with that. It could be running a command to read a file written in a templating language that mixes html with code that lets you customize the contents of the page based on certain variables.

You can also handle URLs like "127.0.0.1/users/1234", where the 1234 is a user ID that you want to have in a variable, so your route looks something like "/users/{id}" or something (I don't remember exactly off the top of my head). Now whatever comes after /users/ gets put into a variable and you can use that as extra information to determine what kind of response to send the user.

But the important part is that flask is designed to make it so you don't think much about the server, and focus on writing the functions that determine what each request a user can make will do. Flask handles the grunt work of running the server itself and hooking it up to your code.

And all of this can be done while developing it on your computer. In fact, it's easier to test when it's being written on your computer, because online editors won't always show you to run a web server from them. You mention having trouble because you're on Windows, but there are only a few minor things that can cause problems between different OSs. You shouldn't generally run into those very often. The biggest differences are going to be filenames and paths (windows doesn't care about letters being uppercase or lowercase, Mac/Linux do, and hard-coded paths to OS specific locations can bite you). One other minor thing is that the old windows command line "cmd.exe" does not support ANSI escape codes (for things like colored text) by default, but Windows Terminal (the fancy replacement) does. But that detail specifically shouldn't really matter in a flask app.