The Student Room Group

Programming Help

If I want to create a project that, suppose, used multiple languages like HTML, CSS and Python, how do compile all of these into a single compiler for my project.
Could you give an example of what you're actually trying to do and what problem you're trying to solve for your project? Are you trying to build a web app and looking for a way to host it?


None of the languages you mention here are compiled ('compiling' is the process of translating a language into some other form - usually something less-readable like assembly language, machine code, or "bytecode"). So the example you've given doesn't really give any clues

On the other hand, it might mean that your problem is fairly simple to solve because the answer is that you wouldn't need to compile them or do anything special with the code - just keep everything "as is"; web browsers are quite happy reading plain text HTML/CSS, and the Python interpreter works with plain text .py files.

With a website, the main thing you'd need to do is serve up your content (HTML and CSS) through some kind of web server, such as nginx or IIS, or if using Python to build a web app then use a framework like Flask or DJango.
(edited 5 years ago)
Reply 2
Original post by winterscoming
Could you give an example of what you're actually trying to do and what problem you're trying to solve for your project? Are you trying to build a web app and looking for a way to host it?


None of the languages you mention here are compiled ('compiling' is the process of translating a language into some other form - usually something less-readable like assembly language, machine code, or "bytecode"). So the example you've given doesn't really give any clues

On the other hand, it might mean that your problem is fairly simple to solve because the answer is that you wouldn't need to compile them or do anything special with the code - just keep everything "as is"; web browsers are quite happy reading plain text HTML/CSS, and the Python interpreter works with plain text .py files.

With a website, the main thing you'd need to do is serve up your content (HTML and CSS) through some kind of web server, such as nginx or IIS, or if using Python to build a web app then use a framework like Flask or DJango.

What I mean, is suppose that I wanted to create a project with a front-end using HTML and CSS and back-end using python. How can I run the project so that the 3 languages “speak” and interact with each other. For example, if I wanted a login page, I could design it using HTML and CSS, but the file containing all the valid users and password combinations would be done via python. How can I run all this together
Original post by Techtech123
What I mean, is suppose that I wanted to create a project with a front-end using HTML and CSS and back-end using python. How can I run the project so that the 3 languages “speak” and interact with each other. For example, if I wanted a login page, I could design it using HTML and CSS, but the file containing all the valid users and password combinations would be done via python. How can I run all this together

Aha, ok - that's a pretty common thing to do, although there are a few steps involved because what you're describing needs to be split between the browser (front end) and a web server (back end).

The short answer is that you probably wouldn't actually write "pure" HTML, and instead you'd use a web app framework on your server, to automatically generate some HTML using Python, and do a lot of heavy lifting with the web app framework. (but of course, the browser wouldn't see any Python, it would only see pure HTML)

Firstly, remember that HTML and CSS are "front end" languages used for the browser. Python is a "back end" language which can be used to build a web service, and it can very easily auto-generate HTML if you use one of its web frameworks, such as Flask or Django.

There's a good tutorial which starts out by doing exactly the thing you're talking about here, using Flask: https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world

Flask uses a hybrid-language called Jinja to auto-generate HTML pages (this doesn't actually solve your login page problem on its own, it's just a piece of the puzzle)

Jinga is the "glue" which auto-generates HTML pages from Python using 'templates' - a Jinja template is just a way of having a server auto-generate HTML instead of writing plain old html pages for yourself -- realistically speaking web developers very rarely write "static" .html pages these days because web servers like Flask and hybrid languages like Jinga are a lot more flexible and powerful for making web apps compared with plain HTML. The reason for using Jinga is that it gives you all the tools you need for using Python to create a fully-blown web app which serves up HTML to the browser.

So, Jinga can help you create the HTML form, which a browser can use to send login data back to Flask (python), but then after that you also need Flask to be able to receive the username/password, and "do something" (e.g. look up in a database), eventually sending something back to the web browser, depending on whether the user had a valid login or not.


Using your login form as an example, it would work something like this:
1) The web browser navigates to a Flask app's "GET" URL for a login page - e.g. http://example.com/login/ (the browser sends an HTTP-GET request)
2) Flask receives the HTTP-GET request from the web browser and passes it into some Python code
3) The Python code uses a Jinja template to automatically generate some HTML
4) the Python code (using Flask) sends the generated HTML back to the web browser in an HTTP-OK response
5) The web browser receives the HTTP-OK response, containing the HTML, and displays the HTML
6) user clicks a <button type="submit"> on the HTML page within the login <form>.
7) the web browser sends an HTTP-POST request to to the Flask app's login URL (e.g. http://example.com/do_login/ ) -- the HTTP-POST contains all the <input> data from the <form> (this is standard web browser Form behaviour, you don't need to worry about this!)
8) Flask receives the HTTP-Post request from the web browser and passes it into some Python code
9) The python code does something with the username and password - e.g. calling into a database to validate the name/password
10) The python code (using flask) sends an HTTP-REDIRECT response
11) the web browser receives the HTTP-REDIRECT response, and then loads a page for the logged-in user.

Don't worry if that sounds like a lot - this is just how the web works (lots of request and response messages to/from the server) - the code to write it is probably simpler than the way I've explained it here. I'd strongly recommend following the first few lessons in the flask tutorial I've linked above - it should all make more sense once you see it working.

Also, the total amount of code you need to actually get this working is barely anything because Flask actually does most of this heavy lifting.
(edited 5 years ago)
Reply 4
Original post by winterscoming
Aha, ok - that's a pretty common thing to do, although there are a few steps involved because what you're describing needs to be split between the browser (front end) and a web server (back end).

The short answer is that you probably wouldn't actually write "pure" HTML, and instead you'd use a web app framework on your server, to automatically generate some HTML using Python, and do a lot of heavy lifting with the web app framework. (but of course, the browser wouldn't see any Python, it would only see pure HTML)

Firstly, remember that HTML and CSS are "front end" languages used for the browser. Python is a "back end" language which can be used to build a web service, and it can very easily auto-generate HTML if you use one of its web frameworks, such as Flask or Django.

There's a good tutorial which starts out by doing exactly the thing you're talking about here, using Flask: https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world

Flask uses a hybrid-language called Jinja to auto-generate HTML pages (this doesn't actually solve your login page problem on its own, it's just a piece of the puzzle)

Jinga is the "glue" which auto-generates HTML pages from Python using 'templates' - a Jinja template is just a way of having a server auto-generate HTML instead of writing plain old html pages for yourself -- realistically speaking web developers very rarely write "static" .html pages these days because web servers like Flask and hybrid languages like Jinga are a lot more flexible and powerful for making web apps compared with plain HTML. The reason for using Jinga is that it gives you all the tools you need for using Python to create a fully-blown web app which serves up HTML to the browser.

So, Jinga can help you create the HTML form, which a browser can use to send login data back to Flask (python), but then after that you also need Flask to be able to receive the username/password, and "do something" (e.g. look up in a database), eventually sending something back to the web browser, depending on whether the user had a valid login or not.


Using your login form as an example, it would work something like this:
1) The web browser navigates to a Flask app's "GET" URL for a login page - e.g. http://example.com/login/ (the browser sends an HTTP-GET request)
2) Flask receives the HTTP-GET request from the web browser and passes it into some Python code
3) The Python code uses a Jinja template to automatically generate some HTML
4) the Python code (using Flask) sends the generated HTML back to the web browser in an HTTP-OK response
5) The web browser receives the HTTP-OK response, containing the HTML, and displays the HTML
6) user clicks a <button type="submit"> on the HTML page within the login <form>.
7) the web browser sends an HTTP-POST request to to the Flask app's login URL (e.g. http://example.com/do_login/ ) -- the HTTP-POST contains all the <input> data from the <form> (this is standard web browser Form behaviour, you don't need to worry about this!)
8) Flask receives the HTTP-Post request from the web browser and passes it into some Python code
9) The python code does something with the username and password - e.g. calling into a database to validate the name/password
10) The python code (using flask) sends an HTTP-REDIRECT response
11) the web browser receives the HTTP-REDIRECT response, and then loads a page for the logged-in user.

Don't worry if that sounds like a lot - this is just how the web works (lots of request and response messages to/from the server) - the code to write it is probably simpler than the way I've explained it here. I'd strongly recommend following the first few lessons in the flask tutorial I've linked above - it should all make more sense once you see it working.

Also, the total amount of code you need to actually get this working is barely anything because Flask actually does most of this heavy lifting.

Thanks for the reply. Just quickly, what is the difference between Flask and Django
Original post by Techtech123
Thanks for the reply. Just quickly, what is the difference between Flask and Django

Well, just two different tools for solving the same problem, but which work in different ways. A bit like comparing Python to Java I suppose.

There's a pretty good comparison here:
https://www.codementor.io/garethdwyer/flask-vs-django-why-flask-might-be-better-4xs7mdf8v

Obviously the person who wrote that prefers Flask instead of Django, but a lot of people prefer Django - which one to pick boils down to personal preference really. Django has some really neat features which you can use out-the-box, although it's bigger so there's more to learn to get things working.

But they're both similar in a lot of ways - e.g. the templates are very similar, and there's loads of support/tutorials/etc. for both.
Reply 6
Original post by winterscoming
Aha, ok - that's a pretty common thing to do, although there are a few steps involved because what you're describing needs to be split between the browser (front end) and a web server (back end).

The short answer is that you probably wouldn't actually write "pure" HTML, and instead you'd use a web app framework on your server, to automatically generate some HTML using Python, and do a lot of heavy lifting with the web app framework. (but of course, the browser wouldn't see any Python, it would only see pure HTML)

Firstly, remember that HTML and CSS are "front end" languages used for the browser. Python is a "back end" language which can be used to build a web service, and it can very easily auto-generate HTML if you use one of its web frameworks, such as Flask or Django.

There's a good tutorial which starts out by doing exactly the thing you're talking about here, using Flask: https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world

Flask uses a hybrid-language called Jinja to auto-generate HTML pages (this doesn't actually solve your login page problem on its own, it's just a piece of the puzzle)

Jinga is the "glue" which auto-generates HTML pages from Python using 'templates' - a Jinja template is just a way of having a server auto-generate HTML instead of writing plain old html pages for yourself -- realistically speaking web developers very rarely write "static" .html pages these days because web servers like Flask and hybrid languages like Jinga are a lot more flexible and powerful for making web apps compared with plain HTML. The reason for using Jinga is that it gives you all the tools you need for using Python to create a fully-blown web app which serves up HTML to the browser.

So, Jinga can help you create the HTML form, which a browser can use to send login data back to Flask (python), but then after that you also need Flask to be able to receive the username/password, and "do something" (e.g. look up in a database), eventually sending something back to the web browser, depending on whether the user had a valid login or not.


Using your login form as an example, it would work something like this:
1) The web browser navigates to a Flask app's "GET" URL for a login page - e.g. http://example.com/login/ (the browser sends an HTTP-GET request)
2) Flask receives the HTTP-GET request from the web browser and passes it into some Python code
3) The Python code uses a Jinja template to automatically generate some HTML
4) the Python code (using Flask) sends the generated HTML back to the web browser in an HTTP-OK response
5) The web browser receives the HTTP-OK response, containing the HTML, and displays the HTML
6) user clicks a <button type="submit"> on the HTML page within the login <form>.
7) the web browser sends an HTTP-POST request to to the Flask app's login URL (e.g. http://example.com/do_login/ ) -- the HTTP-POST contains all the <input> data from the <form> (this is standard web browser Form behaviour, you don't need to worry about this!)
8) Flask receives the HTTP-Post request from the web browser and passes it into some Python code
9) The python code does something with the username and password - e.g. calling into a database to validate the name/password
10) The python code (using flask) sends an HTTP-REDIRECT response
11) the web browser receives the HTTP-REDIRECT response, and then loads a page for the logged-in user.

Don't worry if that sounds like a lot - this is just how the web works (lots of request and response messages to/from the server) - the code to write it is probably simpler than the way I've explained it here. I'd strongly recommend following the first few lessons in the flask tutorial I've linked above - it should all make more sense once you see it working.

Also, the total amount of code you need to actually get this working is barely anything because Flask actually does most of this heavy lifting.

So I can use flask/django to create python + html
what if I want to create a web app using Visual Basic
Original post by Techtech123
So I can use flask/django to create python + html
what if I want to create a web app using Visual Basic

You can create an ASP.NET web app in visual basic:

-ie. open Visual studio, go to the menu File > New > Project
- Then choose 'Visual Basic' > 'Web' > 'ASP.NET Web Application (.NET Framework)'
- Then choose the MVC project template. Then it creates a simple web app with the main 'pieces' in place

ASP.NET has got the same idea as flask/django -- you can use HTML+VB for the "templates", in .vbhtml files. (inside the "Views" folder). ASP.NET is structured so you have to follow its naming conventions - MVC means Model View Controller, which is just a name for a pattern describing how modern web apps are logically organised, and you'd hear the same acronym used in Flask/Django too.

The ASP.NET project gives you folders in the project called Views and Controllers which probably don't appear to be connected to each other just from looking at it, but the ASP.NET MVC "framework" ties everything together for you.

(Django and Flask also use the same basic ideas of model, view, controller. And the Java framework called Spring also uses the same MVC idea/pattern)

The only thing to warn you about is that nearly all the tutorials online for ASP.NET MVC are in C# and the examples all use .cshtml instead (C# + HTML), but you can pretty much substitute anything happening in Visual Basic for C# because they're basically 'sibling' languages which do exactly the same thing with a different syntax. I would personally choose C# if it were me, but there's nothing technically wrong with VB, just the extra brain-work you need to do to substitute C# syntax for VB syntax would probably get frustrating.

https://docs.microsoft.com/en-gb/aspnet/mvc/overview/getting-started/introduction/getting-started
(edited 5 years ago)

Quick Reply

Latest

Trending

Trending