[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
I'm having a hard time understanding Python as a web language.
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 21
Thread images: 2
File: python-logo.png (23 KB, 250x250) Image search: [Google]
python-logo.png
23 KB, 250x250
I'm having a hard time understanding Python as a web language.

In PHP I just write a program file and it runs straight in the browser or inside HTML.


So how does a Python web framework work?

I make a Template file (HTML) filled with variables that link to the Python program file?

So you're writing Python code + Framework markup?

How does everything connect? Because if you try to run pure Python code in the browser it just gives an error.
>>
FUCK YOU
U
C
K

Y
O
U

FUCK YOU
>>
Yeah, you need to run uwsgi or something like that.

But try django
>>
WSGI on whatever server you're hosting it on.
>>
File: 1457999770719.jpg (192 KB, 1200x910) Image search: [Google]
1457999770719.jpg
192 KB, 1200x910
>>53689829
Try me mother fucker
>>
>>53689813
>In PHP I just write a program file and it runs straight in the browser or inside HTML.

What the fuck are you on? PHP is run on the server, not the browser.
>>
>>53689845
But to be honest it sounds to me like you don't quite grasp the entire relationship from code to the browser. Maybe do some research on that first. It might give you some more insight into why your browser doesn't interpret python code or any fucking code whatsoever. (Aside from javascript)
>>
>>53689859
Yeah but once it's in the server all you have to do is go to your .php file in will execute in the browser.
>>
>>53689877
That's assuming if you have a web server module for it. The only reason you can do that is due to historical PHP popularity
>>
>>53689877
No plebian, Apache sees .php files as valid index documents. It then passes this off to PHP which compiles .html pages for you and serves that to the user.

The browser does nothing.
>>
>>53689892
So why can't I visit the .py file in the browser and have Python execute it?
>>
>>53689905
you can. but its not the recommended way to run python.
>>
>>53689813
I think you're looking for something like flask/django OP
>>
>>53689905
You can, provided the server is set up to recognize .py and special markup, and pass the page off to python for processing.

You really are thick aren't you?
>>
>>53689926
>provided the server is set up to recognize .py and special markup

Then why the fuck isn't this automatically set up in Python like it is for PHP?

Is it supposed to be done another way?
>>
>>53689813
Python code on server runs over template, generates HTML based off the python code inside it, sends HTML to browser. This is pretty much what PHP does too, but it looks like its running in the browser if you don't know what it's doing.
>>
>>53689905
okay, let spell this out for you because it's 6am here and clearly I have nothing better to do.

Apache (which is what I am assuming you are using), listens to port 80 for incoming requests.
If you point your browser to a directory i.e. the url does not end in .php, it will go and look for the document root file. These document root files are inside of Apache's config and it will try and find one. Let's say for arguments sake that it finds index.html which is by default the document root file. It will pick this up and simply serve it to the browser as the browser will interpret the HTML file.

Now, Apache has fucking nothing to do with PHP or Python or fucking anything. It has a module called mod_php or whatever. This module allows Apache to serve .php files.

Now same example as above, the user requests for a page and Apache sees this request and finds a .php file instead of a .html file. It DOES NOT SERVE THAT TO THE FUCKING USER. What it does is send the request to the php module to be "converted" for the lack of a better word into HTML for the user. Which it then in turn returns to the user.

>>53689942
You can, but you need the wsgi module for it in Apache. Similarly, without the php mod in apache, your code won't run.

Does that explain it a bit more?

Apache/Python combos are not commonly used. It's mainly served via uwsgi sockets to a web server via reverse proxy like NGINX
>>
>>53689992
If I install webpy framework, is that essentially doing what Apache + wsgi module is doing?

webpy rendered the Template file + Python code into html.
>>
>>53689926
>You really are thick aren't you?
not him, but that's rude. you didn't come to life knowing everything, so let him try to come out of ignorance the way he find easier.
understanding new things by means of already known concepts - accurate or not - is a crutch we all use, no one is 'thick' for doing so.
>>
>>53690043
Kind of but not really. It's literally the most simplistic version of the process :)

The result is the same but never do this in a production environment. If you really want to get into python development for the web, look at http://djangoproject.com

There is a guide here on how to serve up django in a production environment: https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-14-04

I watched a good talk last night regarding this, which you can watch here: https://www.youtube.com/watch?v=Toa9lW8UMOA
>>
A server having some php files on it listens to port 80. When someone wants index.php, he does an HTTP GET request for that file and the server processes that request.

With a webserver designed in Python or whatever it isn't that file centric. You can specify whatever HTTP requests you listen for. In that way you can design an API. Like "GET mygayporn" could be a request that returns all your gayporn in whatever fashion (for APIs json is pretty ok).
GET mygayporn/1 would return only one picture, while DELETE mygayporn/3 would delete picture 3.

So basic bottomline: the old stack based on Apache and PHP handle request mostly based on files, while stuff written in Python or Go handle request based on functions.
Thread replies: 21
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.