Hello, I’m currently using php as my server-side scripting language, I’m wondering if there’s any better alternative (I’m doing a lot of includes so I want those to be short and easy)
what do you find bad about php?
if you’re building on Glitch, you might have a more convenient time with Node.js
Personally I would learn Node.js as this way you can at least take that skill and use it on like discord bots and not limit yourself plus then you get all the packages that node.js has and it will make things a lot easier in some cases. Plus when it comes to possibly getting help we all use node.js mostly so it will be easier for someone to help you and more likely. PHP also is kind of hard to learn as there are significantly less resources to learn from.
I don’t find ‘bad’ with it per say, but I want to make sure I’m using something good, and since I don’t know the alternatives, I thought I’d ask here.
Node.js is not very high on my list of options though. not much a fan of it…
just out of curiosity I hear python can be used as a server side language (I have experience with python), is this complex/how would i set up?
I like python with Flask. there’s python 3.7.10 installed in glitch project containers if you want to play around with that. supposedly glitch even has a “python” project type
how do I use it though? like, with php you name the index file index.php, do you just name it index.py, cause when I do that no index file can be found, do I need to put something into glitch.json
it is quite different. php in that style has “file based routing,” where opening the browser to
mysite.example.com/about/history.php causes your web server to run a file somewhere like
/mysite/about/history.php, with that
/about/history.php in common. the piece of software that listens for the request from the browser and starts up that history.php script is something that you might not even run yourself, e.g. there’s a big shared instance running on a server.
in Flask, there’s a program that’s running and listening for requests from the browser, and opening
mysite.example.com/about/history will call a function as if a piece of code had done
handle_request('/about/history') (this is a bit simplified, look up WSGI for the actual interface). and you can have
handle_request(path) later look up a file with
path if you want, but it’s up to you, and it’s all in a program that you run. so you’re not creating a
/mysite/about/history.py file; rather, you’re creating, for example
/mysite/server.py that contains such a
of course you don’t have to write this whole elaborate
handle_request function. Flask makes it so you can define write a bunch of functions decorated with
@app.route('/about/history') and similar, and
app will be that function that can handle requests.
they have a tutorial if you want to take a look at what some simple apps would look like
I’ve been changing the server side language from php to python over the last few days, here’s my progress: SM | HOME (sandmuel.glitch.me)
it’s working fine, but I’m wondering a few things. mainly with the way I’m setting the title. I’d like to know if the approach I’m using is appropriate, or just a ‘workaround’ type of method. here’s the source: Glitch :･ﾟ✧
(I’m using a macro for something but don’t know if there’s a better approach)
also, do you by any chance know how to use Gunicorn?
I’ve usually seen it done as the
<title> element in the outer layout template having a “block” that your inner page provides. see the example here: Template Designer Documentation — Jinja Documentation (3.0.x)
haven’t tried. does the quickstart on their website work? https://gunicorn.org/
I had attempted something like this, but I believe it only works if the block is directly in the base, due to the base includes being processed before the child page. this leads to overwriting blocks after they have already been used by flask.
(Though do let me know if I am wrong, I may have just been going about it incorrectly.)
And as for Gunicorn, thanks for the link, I’ll take a look at the website
dang that’s a lot more about macros than I knew. is there any hope that importing those macros “with context” can help?
That’s what I’m doing, and it works. I just don’t know if it’s the best approach…
gunicron, waitress and similar programs run your program in a production ready manner.
You might notice that some people put their
if __name__ == "__main__". This is because the
app.run is usually used for development and in production gunicorn or waitress is called via a script or the command line with the instructions on how import your app as a module.
this might be wrong though as the last time i did flask was approx 4 years ago.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.