Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Updates per Adrian#2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kraigb merged 5 commits intomasterfromkraigb-issue001
Jul 11, 2018
Merged

Updates per Adrian#2

kraigb merged 5 commits intomasterfromkraigb-issue001
Jul 11, 2018

Conversation

@kraigb
Copy link
Contributor

Address issue#1

@kraigbkraigb mentioned this pull requestJul 11, 2018
Copy link

@ThiefMasterThiefMaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You might want to runpycodestyle (successor of thepep8 cli) to check if it reports any issues.


fromflaskimportFlask,render_template

fromHelloFlaskimportapp

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I would go forhello_flask sincesnake_case names are more common for most python packages (some old stdlib packages aside, but unfortunately many older parts of stdlib aren't the best example for naming anyway)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, good point given that I made that piece a module and not just a folder name.


returnrender_template(
"hello_there.html",
title='Hello, Flask',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

no space before=

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

OK

title='Hello, Flask',
message="Hello there, "+name+"!",
date=now.strftime("%A, %d %B, %Y at %X")
name=clean_name(name),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

no spaces around=

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

OK

message="Hello there, "+name+"!",
date=now.strftime("%A, %d %B, %Y at %X")
name=clean_name(name),
date=datetime.now()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

no spaces around=

fromflaskimportFlask
fromflaskimportrender_template
fromdatetimeimportdatetime
fromreimportmatch

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

usually people justimport re and then usere.match() - this also avoids shadowing when people assignmatch = ... to the actual match object

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Makes sense...I'm still unclear when it's good to import a module as a whole vs. importing the part you need. :)

returnapp.send_static_file('data.json')
returnapp.send_static_file('data.json')

defclean_name(name):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this is not really needed, since any variable passed to jinja is considered unsafe by default so any HTML there will be escaped

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Of course...I had it there in an intermediate step of the tutorial when I was just generating a plain text response, so I can omit it from the final version. Thanks for the reminder.

defclean_name(name):
# Filter the name argument to letters only using regular expressions. URL arguments
# can contain arbitrary text, so we restrict to safe characters only.
match_object=match("[a-zA-Z]+",name)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If you decide to keep it, I would replace this whole function with the much more simple:

return re.sub(r'[^a-zA-Z]+', '', name) or 'Friend'

ther prefix for the string is not needed here, but I think it's good practice to always use raw strings for regexps (so you don't forget it when adding something with a backslash later)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'll be omitting all that extra code anyway.

<spanclass="message">{{message }}</span> It's {{ date }}.
<spanclass="message">Hello there,{{name }}!</span> It's {{ date.strftime("%A, %d %B, %Y at %X") }}.
</body>
</html>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

file doesn't have an ending linebreak. not pretty when youcat such a file in a terminal 😿

sounds like VS code actually has an option for this:microsoft/vscode#1666
dunno if it's enabled by default though (I hope it is)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

"files.insertFinalNewline": true is the setting, but it's false by default. :(

@kraigb
Copy link
ContributorAuthor

@ThiefMaster, take one more look. Renaming the folder means the diffs are gone, but the code is short and should have all the changes you requested.


@app.route('/')
defhome():
returnrender_template("home.html",title="Home")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'd move that to the template using another{% block %}

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't understand what you mean. Is there a default rendering for / that we'd take advantage of here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I just meant thetitle="..." since that's something you'd usually put in your template.

Therender_template calls you need to keep

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ah, I see. Thanks.

@kraigb
Copy link
ContributorAuthor

Added the content block and revised the templates. Let me know if there's anything else, and thanks for your help!

@kraigbkraigb merged commit042a160 intomasterJul 11, 2018
@kraigbkraigb deleted the kraigb-issue001 branchJuly 11, 2018 18:44
caioroscelly added a commit to caioroscelly/python-sample-vscode-flask-tutorial that referenced this pull requestJun 10, 2024
MridulMoitra pushed a commit to MridulMoitra/python-sample-vscode-flask-tutorial that referenced this pull requestJul 31, 2024
AzureRM Terraform Provider Contribution Guide
MridulMoitra pushed a commit to MridulMoitra/python-sample-vscode-flask-tutorial that referenced this pull requestJul 31, 2024
MridulMoitra pushed a commit to MridulMoitra/python-sample-vscode-flask-tutorial that referenced this pull requestJul 31, 2024
MridulMoitra pushed a commit to MridulMoitra/python-sample-vscode-flask-tutorial that referenced this pull requestJul 31, 2024
…t-labFix 101-devtest-labs automation test by adding some default value for variables
AdamZ45 added a commit to AdamZ45/python-sample-vscode-flask-tutorial that referenced this pull requestApr 22, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@ThiefMasterThiefMasterThiefMaster left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@kraigb@ThiefMaster

[8]ページ先頭

©2009-2025 Movatter.jp