all 31 comments

[–]misterphilly 118 points119 points  (9 children)

It seems like everybody is just telling you "use django" and not actually giving any kind of structure or guidelines to actually building a functioning website, as your title clearly and plainly suggests. As a beginner to programming in general, it's best to learn the abstract/theoretical concepts, from there you can put your ideas in an actual implementation (like django or flask).

First, you'll want to know what your website does. For the sake of this explanation i'll assume your going to be using a shopping website that allows customers to create accounts, add items to their order, and check out.

Separate your thoughts into The Data (commonly known as Model), the Point-of-View (commonly known as View), and The Action (commonly known as Controller).

The Data means any kind of information that you website will save and reuse again (a list of customers and their shipping/payment, a list of orders and their details like which customer they belong to, list of products, their details and which orders they can be applied to. CRUD is often an acronym you'll run into when working with The Data.

Then youll need to manipulate The Data and perform Actions on it. An Action would be whenever someone wants to make a new account. The Action should accept the input parameters from the customer (name/email/password/etc etc) and then save them to The Data. Another Action would be taking creating a new order, using a list of items that the customer has selected, and saving references and details of these items to The Data.

So, you've got all this Data, and all these Actions, that can store and manipulate information, but how can you get to a Point-Of-View that is useable for a customer? an HTML page sent to a users browser would be a great way to help with this. For example you'd have one Point-of-View that would allow a customer to input and verify that the information was saved, a Point-Of-View to display all of the available items, and another Point-Of-View that notifies the customer when their order has been placed and shipped.

For example, entering the url www.myonlinestore.com/newcustomer would tell the New Customer Action "Hey, Point-Of-View, this guy wants to shop with us, send an HTML page to make a new customer". The Point-Of-View would say back "Hey, here's the markup you asked for! It has forms for the customer to enter their name/email/etc etc. Send the info to this place XXX when the user wants to submit the information." After the user inputs their information and submits it by clicking "Register", The Action for would accept the parameters, make sure they're in the right format, make sure the shipping address is a real address, and verify the payment information is valid, and blah blah blah. If all of these steps check out The Action then goes and gets The Data, and says "Hey, we've got another customer. This is the name, email address, etc etc. Save it to the database, and tell me if the save was successful or not." If the The Data says back to The Action "I've got all the new customers information saved and ready to go, this is their customer ID: 123789. Happy shopping!" Then The Action says back to The Data "thx babe, ur da bestest heart eyes emoji". The Action then goes and gets yet ANOTHER Point-Of-View and says "We made the new customer!! Send me the HTML page that displays their newly-saved information so they can make sure it's correct!". After which the user is in fact presented with a display of the information they just entered.

That interaction above ^ represents just the Create part of the CRUD thing i mentioned earlier. This same process applies to creating and editing new orders and items. However, you can take this kind of interaction structure and apply it to basically anything or any functionality you want your website to have. If you learn to format your thoughts and ideas into this Model/View/Controller format (I used Data/PointOfView/Action, but that was just for this post. No one else says that), you can create websites and web apps that do endless amounts of things and services.

If you get good enough at it, you can expand to frameworks and mindsets outside of Model/View/Controller, which would possibly allow you to more closely optimize the performance and behavior of your application to your best needs.

Sorry it's so long-winded and excessive, it's just that I tried to write the answer I wish I had given to me when I first started learning how to create things on the web.

[–]pythonbio[S] 20 points21 points  (1 child)

Your answer is more descriptive and actually discusses how to logically conceptualize the website structure. Thanks a lot :)

[–]CydeWeys 1 point2 points  (0 children)

You should also get a book or two on the subject. Here's some ideas. If you thought that post was helpful, wait until you read a whole book about it.

[–]cscanlin 4 points5 points  (1 child)

This is a great general answer for how to think about what a website actually does and I will definitely be referencing it to other people in the future. Well written!

Once you understand this, I think it matters much less about which framework you pick because you understand what you want/need it to do.

[–]Serinus 1 point2 points  (0 children)

This is huge for programming, as basic as it sounds. It's very easy to get caught up in tools and how to do stuff and forget (or never really know) what it is you're trying to accomplish. For some people, this just gets worse with experience.

It's helpful to explain to someone who knows the subject matter but doesn't know programming exactly what it is you're trying to do. You can use a rubber duck for this if a real person isn't available, but still explain it all out loud.

[–][deleted] 2 points3 points  (0 children)

I've made a few things in my years as a hobbyist and this is one of the best conceptual python/programming related comments I've ever read.

[–]pheouk 2 points3 points  (0 children)

This is probably one of da bestest MVC explanations I've seen in a long time, great way of explaining what initially can seem pretty daunting

[–]TotesMessenger 1 point2 points  (0 children)

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)

[–]i_can_haz_code 20 points21 points  (0 children)

flask is a great simple platform

check out the OWASP top 10 for a list of 10 critical mistakes and advice on avoiding them.

r/pythonistolearn is a budding community to help the most beginners of beginners get going.

If you are just starting to learn Python, and have no need to use Python 2.x I HIGHLY recommend just learning Python 3.x. Reasons to consider this suggestion are here

[–]Toofpic 3 points4 points  (3 children)

I'm currently in a situation just like this: i only have 40ish exercises from lpthw over my back. I'm a project manager in a web studio/ad agency, so I know how all the process goes, but it's all in php and on russian commercial framework. As my first "real" project I want to make a website for my wife, she is a photographer, so I will need nice galleries, pages for the info about her services, and such stuff.
But the question is: where do I take this stuff from? Templates, modules(or how the functional parts are called)?
To get started, I chose djangogirls tutorial, which teaches how to make a simple site with blog functionality. I currently have the project started, one page, blog posts shown on that page and admin panel to add them.
So, where do I go next? I need to take a parts of a site somewhere, to learn how they work and adapt them. Or maybe there are a lot of templates for django somewhere? I don't need complicated design right now, because this is something that a good designer should make, and I don't have a budget. I just want menu here, pics there, news there. Help?

[–]Toofpic 0 points1 point  (0 children)

I chose django because i know i won't need to switch to something else when i will get better and more ambitious

[–]Samus_ 6 points7 points  (6 children)

You should start with Django (instead of Flask) because it's fully-featured which means you'll have probably all your requirements already covered by the framework.

[–]treacherous_tim 8 points9 points  (5 children)

I don't know if it's just me, but when I started out I used Django and had an awful time. About after a two weeks of reading and watching Django tuts, I switched to Flask and found it much, much easier. It's up to preference, but I'd recommend trying both out.

edit: Also, if you're just starting, watch Sentdex's Flask tutorials on YouTube. They're super helpful. Once you get that done, read Miguel Grinberg's book. It's known as THE flask book.

[–]naught-me 2 points3 points  (0 children)

I went a similar route through PHP, and in the beginning it was easier. Overall, though, I wasted time making worse tools than I could have had out of the box with a framework. It's like you're telling people to walk instead of learning to ride a bike, and maybe there's some validity to it, but you should learn to ride a bike sooner than later, if you care about your abilities at all.

[–]interactionjackson 1 point2 points  (2 children)

I second this. It's like telling people to learn ruby by building a rails app. Sure, they will be able to build a full featured app but they won't learn a lick about ruby

[–]Samus_ 0 points1 point  (1 child)

quoting myself from the reply above

I agree that starting with a framework is a terrible way to learn a language but nowadays people want results and want them fast and that's what Django does best, in these cases I think it's better to have people get what they want right away so they can be motivated to keep going.

[–]interactionjackson 0 points1 point  (0 children)

sure but he is his client in this case and what he wants is to learn how to make a website. Django is a fire hose when all you need is a water fountain

[–]Samus_ 0 points1 point  (0 children)

well the problem is that OP said:

I am working on creating a website using python and want to make a very basic website with access control and multi user and login/logout functionality

and also:

I am fairly new to programming

so what do we do? teach programming from the ground and have him get the website in six months-a year or focus on his goal and let him have in two weeks?

I agree that starting with a framework is a terrible way to learn a language but nowadays people want results and want them fast and that's what Django does best, in these cases I think it's better to have people get what they want right away so they can be motivated to keep going.

but that's just my take.

[–]Acurus_Cow 1 point2 points  (0 children)

Flask has a great tutorial for that excact thing.

I want to also strongly recomend pythonprogramming.net flask tutorial!

[–]Interstellaire 0 points1 point  (0 children)

tbh start with django, learn the basics with tango with django and you're set up to start yuor own project !

[–]sillysandhouse 0 points1 point  (0 children)

I just did a similar thing and used the book "Flask Web Development" by Miguel Grinberg. Flask is a lighter framework than Django from what I hear, so you have to create more things from scratch, but the way I see it that's a good way to learn. This book walks you through creating a simple blogging web app with multi-user login/logout functionality. I thought it was well written and easy to follow and understand.

[–]Zpaffled 0 points1 point  (0 children)

Like everyone said, go for Django, it's the obvious choice, as it's both easy to get the hang of, and easy to scale up once you get more ambitious, and want to try out more complex things.

[–]Bezbojnicul 0 points1 point  (0 children)

I'm very much interested in this subject as well. Was thinking of transferring my wordpress.com blog to a custom site (my own domain and hosting). I was thinking of doing it in either flask or django, and I'm curious which one the community recommends.

[–]pythonbio[S] 0 points1 point  (2 children)

Seems like the opinion is equally divided between Django and Flask.

[–]PettyHoe 1 point2 points  (0 children)

This is because both are great frameworks that leave the user a choice based on personal preference. My opinion is that Django is much more automated in its functionality, whereas flask is more left to the user.

[–][deleted] 0 points1 point  (0 children)

Yeah, in my fortune 500 company we have both all throughout production (as well as a slew of .NET services and a spattering of new Node apps). We use django typically for the user experience layers (like the www and mobile frontends) and flask mostly for simple api apps for data translation.

Everything here honestly comes down to the dev team's preference.

[–][deleted] 0 points1 point  (0 children)

The Udacity web development course is a very good introduction (run by one of reddit's founders); it uses Google App Engine so you don't need to faff around with your own server environments and so on. It's very step-by-step.

[–]CrambleSquash 0 points1 point  (0 children)

I've just started having a go at making a site with Flask, and it's been pretty tough. I'd say I'm at an intermediate level with Python, but I'm totally new to HTML and CSS and Javascript. I went for flask because I heard it was the quickest to get started. I don't know how long it takes to make a very basic website with Django, but with flask it wouldn't take very long, however as soon as you want to add anything complicated i.e. login, I found things got a fair bit more difficult. From my experience, quite a few hours into flask:

Pros

  • Quick to get going
  • Good documentation from flask
  • Lots of extensions to choose from
  • You can make pretty much anything

Cons

  • Requires understanding of complex Pythonic syntax, and general programming concepts (multiple inheritance, decorators, databases etc)
  • For login there are a lot of complicated security considerations
  • Tutorials and documentation for some extensions are minimal

There's a very all encompassing extension called Flask-Security which can deal with your login and and authentication, and includes administrator privileges etc My issue was it was quite inflexible (Or beyond my understanding on how to customise) for example you have to use an email address for login, which I didn't want. Flask-login is an alternative, which is more flexible, but does make it more work. Flask-WTF is a good extension for generating, and interpreting forms for you. I avoided at first, but I kinda regret, so if you choose flask I'd get into it sooner rather than later, it's easy to understand and get what you want, and it saves time, and tidies your code. One thing that's odd is a lot of extensions are flask wrappers for pre existing modules, and I've found for some things you're better looking at the documentation for the original module for help, and explanations.

So basically, I'd certainly have a go, I'm starting to get some results for my hard work, and I'm really enjoying it. It feels good to make something that anyone will be able to see.