{"action":"created","comment":{"url":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/comments/35592126","id":35592126,"diff_hunk":"@@ -553,14 +562,137 @@ And voila! Now if we go to `http://localhost:5000/blog/`, you should see a list\n \n ## 5.0 Working with Forms\n \n-Coming soon!  See the code in the `blask-5/` folder!\n+*Work in progress-  See the code in the `blask-5/` folder for reference*\n+\n+So now you can display blog posts, but how can you add new blogposts to the database? With forms!\n+The Flask framework has the WTForms library built-in, so you don't need to install any new packages. Let's get started!\n+\n+### Instructions\n+\n+Add a Secret Key to `app/__init__.py` . This allows you to make the database only approve forms if they're submitted from within the app.\n+```python\n+app.config['DEBUG'] = True\n+app.config['MONGODB_SETTINGS'] = {'db': 'blask'}\n+app.config['SECRET_KEY'] = 'another random string'\n+```\n+\n+Now let's edit the `model/blog.py` file. Import the `model_form` function and call it on the BlogPost class at the bottom.\n+```\n+from app import db\n+from flask.ext.mongoengine.wtf import model_form\n+\n+class BlogPost(db.Document):\n+    ...\n+\n+BlogPostForm = model_form(BlogPost)\n+```\n+\n+Now the database knows what a new form looks like, but how does the form get there? Let's edit the `routes/blog.py` file.\n+\n+First, import the `redirect, url_for, request` functions from flask (covered in the [previous tutorial](http://learn.adicu.com/webdev/)). \n+\n+Then, add the BlogPostForm object that we just declared in `models/blog.py` from app.models.blog\n+\n+```\n+from flask import Blueprint, render_template, redirect, url_for, request\n+from app.models.blog import BlogPost, BlogPostForm\n+...\n+```\n+\n+It's time to setup a new route! If you did the previous tutorial, the code will be familiar. Add this to the bottom of `routes/blog.py`\n+```\n+@blog.route('/new', methods=['GET', 'POST'])\n+def new():\n+    \"\"\"Create a new post\"\"\"\n+    form = BlogPostForm(request.form)\n+\n+    if request.method == 'POST' and form.validate():\n+        form.save()\n+        return redirect(url_for('blog.blog_page'))\n+\n+    return render_template('new.html', form=form)\n+```\n+If a form is submitted to the `localhost:5000/blog/new route`, `form.validate()` will compare the csrf_token with the secret key. If everything is valid, the form will be saved to the database. Otherwise, the user will be redirected to the form submission page. Note that the rendered form is auto-populated with the fieldnames of a BlogPostForm object. To make use of them though, you'll still need to know what properties to render in your HTML page. ","path":"README.md","position":92,"original_position":92,"commit_id":"82ba9bf1618add64f59ba51f29322a003b01bd40","original_commit_id":"82ba9bf1618add64f59ba51f29322a003b01bd40","user":{"login":"danrschlosser","id":2433509,"avatar_url":"https://avatars.githubusercontent.com/u/2433509?v=3","gravatar_id":"","url":"https://api.github.com/users/danrschlosser","html_url":"https://github.com/danrschlosser","followers_url":"https://api.github.com/users/danrschlosser/followers","following_url":"https://api.github.com/users/danrschlosser/following{/other_user}","gists_url":"https://api.github.com/users/danrschlosser/gists{/gist_id}","starred_url":"https://api.github.com/users/danrschlosser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danrschlosser/subscriptions","organizations_url":"https://api.github.com/users/danrschlosser/orgs","repos_url":"https://api.github.com/users/danrschlosser/repos","events_url":"https://api.github.com/users/danrschlosser/events{/privacy}","received_events_url":"https://api.github.com/users/danrschlosser/received_events","type":"User","site_admin":false},"body":"`localhost:5000/blog/new` route (moved the tick)","created_at":"2015-07-27T21:54:54Z","updated_at":"2015-07-27T21:54:54Z","html_url":"https://github.com/danrschlosser/intermediate-flask/pull/2#discussion_r35592126","pull_request_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/comments/35592126"},"html":{"href":"https://github.com/danrschlosser/intermediate-flask/pull/2#discussion_r35592126"},"pull_request":{"href":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/2","id":40952914,"html_url":"https://github.com/danrschlosser/intermediate-flask/pull/2","diff_url":"https://github.com/danrschlosser/intermediate-flask/pull/2.diff","patch_url":"https://github.com/danrschlosser/intermediate-flask/pull/2.patch","issue_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/issues/2","number":2,"state":"open","locked":false,"title":"Filled out Section 5","user":{"login":"hydrosquall","id":9020979,"avatar_url":"https://avatars.githubusercontent.com/u/9020979?v=3","gravatar_id":"","url":"https://api.github.com/users/hydrosquall","html_url":"https://github.com/hydrosquall","followers_url":"https://api.github.com/users/hydrosquall/followers","following_url":"https://api.github.com/users/hydrosquall/following{/other_user}","gists_url":"https://api.github.com/users/hydrosquall/gists{/gist_id}","starred_url":"https://api.github.com/users/hydrosquall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydrosquall/subscriptions","organizations_url":"https://api.github.com/users/hydrosquall/orgs","repos_url":"https://api.github.com/users/hydrosquall/repos","events_url":"https://api.github.com/users/hydrosquall/events{/privacy}","received_events_url":"https://api.github.com/users/hydrosquall/received_events","type":"User","site_admin":false},"body":"Filled out Section 5 + Proposed Section 6.","created_at":"2015-07-27T21:42:37Z","updated_at":"2015-07-27T21:54:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1ac2be58a2ab6b5801dc0333b3c1c4eb714d73ff","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/2/commits","review_comments_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/2/comments","review_comment_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/comments{/number}","comments_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/issues/2/comments","statuses_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/statuses/82ba9bf1618add64f59ba51f29322a003b01bd40","head":{"label":"hydrosquall:master","ref":"master","sha":"82ba9bf1618add64f59ba51f29322a003b01bd40","user":{"login":"hydrosquall","id":9020979,"avatar_url":"https://avatars.githubusercontent.com/u/9020979?v=3","gravatar_id":"","url":"https://api.github.com/users/hydrosquall","html_url":"https://github.com/hydrosquall","followers_url":"https://api.github.com/users/hydrosquall/followers","following_url":"https://api.github.com/users/hydrosquall/following{/other_user}","gists_url":"https://api.github.com/users/hydrosquall/gists{/gist_id}","starred_url":"https://api.github.com/users/hydrosquall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydrosquall/subscriptions","organizations_url":"https://api.github.com/users/hydrosquall/orgs","repos_url":"https://api.github.com/users/hydrosquall/repos","events_url":"https://api.github.com/users/hydrosquall/events{/privacy}","received_events_url":"https://api.github.com/users/hydrosquall/received_events","type":"User","site_admin":false},"repo":{"id":39785151,"name":"intermediate-flask","full_name":"hydrosquall/intermediate-flask","owner":{"login":"hydrosquall","id":9020979,"avatar_url":"https://avatars.githubusercontent.com/u/9020979?v=3","gravatar_id":"","url":"https://api.github.com/users/hydrosquall","html_url":"https://github.com/hydrosquall","followers_url":"https://api.github.com/users/hydrosquall/followers","following_url":"https://api.github.com/users/hydrosquall/following{/other_user}","gists_url":"https://api.github.com/users/hydrosquall/gists{/gist_id}","starred_url":"https://api.github.com/users/hydrosquall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydrosquall/subscriptions","organizations_url":"https://api.github.com/users/hydrosquall/orgs","repos_url":"https://api.github.com/users/hydrosquall/repos","events_url":"https://api.github.com/users/hydrosquall/events{/privacy}","received_events_url":"https://api.github.com/users/hydrosquall/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hydrosquall/intermediate-flask","description":"A look at some intermediate Flask features","fork":true,"url":"https://api.github.com/repos/hydrosquall/intermediate-flask","forks_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/forks","keys_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/teams","hooks_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/hooks","issue_events_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/issues/events{/number}","events_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/events","assignees_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/assignees{/user}","branches_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/branches{/branch}","tags_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/tags","blobs_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/git/refs{/sha}","trees_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/statuses/{sha}","languages_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/languages","stargazers_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/stargazers","contributors_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/contributors","subscribers_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/subscribers","subscription_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/subscription","commits_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/commits{/sha}","git_commits_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/git/commits{/sha}","comments_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/comments{/number}","issue_comment_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/issues/comments{/number}","contents_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/contents/{+path}","compare_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/merges","archive_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/downloads","issues_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/issues{/number}","pulls_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/pulls{/number}","milestones_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/milestones{/number}","notifications_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/labels{/name}","releases_url":"https://api.github.com/repos/hydrosquall/intermediate-flask/releases{/id}","created_at":"2015-07-27T16:26:45Z","updated_at":"2015-07-27T16:26:45Z","pushed_at":"2015-07-27T21:40:13Z","git_url":"git://github.com/hydrosquall/intermediate-flask.git","ssh_url":"git@github.com:hydrosquall/intermediate-flask.git","clone_url":"https://github.com/hydrosquall/intermediate-flask.git","svn_url":"https://github.com/hydrosquall/intermediate-flask","homepage":null,"size":386,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"danrschlosser:master","ref":"master","sha":"16a5947f2ff89f930e965600816e50727f778439","user":{"login":"danrschlosser","id":2433509,"avatar_url":"https://avatars.githubusercontent.com/u/2433509?v=3","gravatar_id":"","url":"https://api.github.com/users/danrschlosser","html_url":"https://github.com/danrschlosser","followers_url":"https://api.github.com/users/danrschlosser/followers","following_url":"https://api.github.com/users/danrschlosser/following{/other_user}","gists_url":"https://api.github.com/users/danrschlosser/gists{/gist_id}","starred_url":"https://api.github.com/users/danrschlosser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danrschlosser/subscriptions","organizations_url":"https://api.github.com/users/danrschlosser/orgs","repos_url":"https://api.github.com/users/danrschlosser/repos","events_url":"https://api.github.com/users/danrschlosser/events{/privacy}","received_events_url":"https://api.github.com/users/danrschlosser/received_events","type":"User","site_admin":false},"repo":{"id":26510961,"name":"intermediate-flask","full_name":"danrschlosser/intermediate-flask","owner":{"login":"danrschlosser","id":2433509,"avatar_url":"https://avatars.githubusercontent.com/u/2433509?v=3","gravatar_id":"","url":"https://api.github.com/users/danrschlosser","html_url":"https://github.com/danrschlosser","followers_url":"https://api.github.com/users/danrschlosser/followers","following_url":"https://api.github.com/users/danrschlosser/following{/other_user}","gists_url":"https://api.github.com/users/danrschlosser/gists{/gist_id}","starred_url":"https://api.github.com/users/danrschlosser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danrschlosser/subscriptions","organizations_url":"https://api.github.com/users/danrschlosser/orgs","repos_url":"https://api.github.com/users/danrschlosser/repos","events_url":"https://api.github.com/users/danrschlosser/events{/privacy}","received_events_url":"https://api.github.com/users/danrschlosser/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/danrschlosser/intermediate-flask","description":"A look at some intermediate Flask features","fork":false,"url":"https://api.github.com/repos/danrschlosser/intermediate-flask","forks_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/forks","keys_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/keys{/key_id}","collaborators_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/teams","hooks_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/hooks","issue_events_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/issues/events{/number}","events_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/events","assignees_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/assignees{/user}","branches_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/branches{/branch}","tags_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/tags","blobs_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/git/refs{/sha}","trees_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/git/trees{/sha}","statuses_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/statuses/{sha}","languages_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/languages","stargazers_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/stargazers","contributors_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/contributors","subscribers_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/subscribers","subscription_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/subscription","commits_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/commits{/sha}","git_commits_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/git/commits{/sha}","comments_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/comments{/number}","issue_comment_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/issues/comments{/number}","contents_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/contents/{+path}","compare_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/compare/{base}...{head}","merges_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/merges","archive_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/downloads","issues_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/issues{/number}","pulls_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls{/number}","milestones_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/milestones{/number}","notifications_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/labels{/name}","releases_url":"https://api.github.com/repos/danrschlosser/intermediate-flask/releases{/id}","created_at":"2014-11-12T00:04:02Z","updated_at":"2015-04-18T17:28:56Z","pushed_at":"2015-07-27T21:42:37Z","git_url":"git://github.com/danrschlosser/intermediate-flask.git","ssh_url":"git@github.com:danrschlosser/intermediate-flask.git","clone_url":"https://github.com/danrschlosser/intermediate-flask.git","svn_url":"https://github.com/danrschlosser/intermediate-flask","homepage":null,"size":494,"stargazers_count":4,"watchers_count":4,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/2"},"html":{"href":"https://github.com/danrschlosser/intermediate-flask/pull/2"},"issue":{"href":"https://api.github.com/repos/danrschlosser/intermediate-flask/issues/2"},"comments":{"href":"https://api.github.com/repos/danrschlosser/intermediate-flask/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/danrschlosser/intermediate-flask/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/danrschlosser/intermediate-flask/statuses/82ba9bf1618add64f59ba51f29322a003b01bd40"}}}}