Getting Started with PowerShell Jump Start Susan Ibach | Technical Evangelist Christopher Harrison | Content Developer
Meet Susan Ibach| @hockeygeekgirl Technical Evangelist Helping developers understand Visual Studio, app building Microsoft Certified Trainer My first program was written in basic on a computer with 64K of memory Will not admit how many years coding experience Basic, Fortran, COBOL, VB, C#, HTML, Python Frequent blogger and presenter marathoner, wife, and mother of two awesome boys!
Meet Christopher Harrison | @geektrainer Content Developer Focused on ASP.NET and Office 365 development Microsoft Certified Trainer Still misses his Commodore 64 Long time geek Regular presenter at TechEd Periodic blogger Certification advocate Marathoner, husband, father of one four legged child
Course Topics Getting Started with PowerShell 01 | Flask application design 04 | Python to databases 02 | Object oriented programming 05 | Jinja layouts 03 | Introduction to databases 06 | Introduction to Bootstrap
Setting Expectations Target Audience New Python developers looking to take the "next step" Burgeoning web developers Some Python experience Suggested Prerequisites/Supporting Material Introduction to Programming with Python MVA
Join the MVA Community! Microsoft Virtual Academy Free online learning tailored for IT Pros and Developers Over 1M registered users Up-to-date, relevant training on variety of Microsoft products “Earn while you learn!” Get 50 MVA Points for this event! Visit http://aka.ms/MVA-Voucher Enter this code: SQLPythonFlask (Exp: 4/6/2015)
01 | Flask Design Susan Ibach | Senior Technical Evangelist Christopher Harrison | Content Developer
Flask is a unique platform... It provides a way to create web applications... Without forcing you into a structure
When your application grows, things can get messy Code duplication Spaghetti code Debugging issues Performance issues
Flask Design Design concepts Packages
Design concepts
I find it immensely helpful to work on the assumption that I am too stupid to get things right. This leads me to conservatively use what has already been shown to work, to cautiously test out new ideas before committing to them, and above all to prize simplicity. - Jonathan Edwards http://alarmingdevelopment.org/?p=79
When doing design... Keep it simple! Use what's already there Don't be afraid of using an existing framework Don't let pride get in the way of using someone else's code Make changes as needed Design with change in mind, because there will always be changes
Core concepts Write once, use everywhere Use layers Use patterns Copy/paste is bad Even if it's just two lines of code Especially if it's a string that could change like a server name Use layers Each layer has a job Data access layer is responsible for getting data from a database Business logic layer is responsible for enforcing rules Use patterns
What's a pattern? A pattern is a recipe to be used to solve a problem Recipes do not need to be followed exactly Substitutions are made based on allergies, ingredients on hand, personal preferences, etc. Use what fits, and modify where it doesn't
Introducing Model, View, Controller (MVC) MVC is a pattern Three basic parts Model, which is your data View, which is what the user will see Controller, which takes the user request and gets the job done
Models, Views, and Controllers 01: Exploring ASP.NET MVC 4 What does MVC look like? Request Controller Retrieves Model “Does Stuff” user Model Response View Visually represents the model
How about an analogy? Think about being at a restaurant Your server is the controller He's responsible for taking your order, going back to the kitchen to get your order, and delivering it The food is the model That's what you're trying to get The plate and other accoutrements are the view It's all about the presentation
How does this apply to Flask?
Packages
What is a package? A packaged block of code Folders and modules Folders become containers The modules are inside of folders
Why use packages? We can't keep adding code to a single file We can't keep adding files to a single folder
Different packages for different portions of your application admin data dataaccess.py models user.py permission.py quiz data dataaccess.py models question.py category.py
How do you create a package? A package at the end of the day is a folder The folder can contain py files and other folders Each folder must contain a file called __init__.py That is two underscores on each side It's a keyword, just go with it It's the first file that will be called Use it to initialize the environment, import files, etc.
How do you reference items in a package? Use dotted notation Method inside server.py? admin.data.server.method() Method inside question.py? quiz.models.question.method() admin data server.py models user.py permission.py quiz data dataaccess.py models question.py category.py
Adding packages to our application