Skip to content

Instantly share code, notes, and snippets.

@duyet
Last active March 30, 2018 03:42
Show Gist options
  • Select an option

  • Save duyet/68874ee06bb7fba7c3e05ce000a4463b to your computer and use it in GitHub Desktop.

Select an option

Save duyet/68874ee06bb7fba7c3e05ce000a4463b to your computer and use it in GitHub Desktop.

1. Design static page

Like this: http://getbootstrap.com/docs/4.0/examples/pricing/

Folder structure like this:

├── app.py
├── statis
│   ├── css
│   ├── image
│   └── js
└── templates
    ├── manage_message.html
    └── pricing.html

Require:

  • Using jQuery, ajax
  • Click to Contact button --> Open model with contact form.
  • Contact model form must be check valid data before send.
    • Check "Name": minimum number of characters is 6
    • Check "Email": must be a valid email address
    • Check "Message": not null
    • Show Success message after submit Contact form

2. Create simple Flask server

GET /pricing

https://i.imgur.com/Wx6ZyGU.png

GET /manage_message

https://i.imgur.com/5xU92yY.png

API:

POST /api/send_message

Request body

{
   "email": "me@duyet.net",
   "name": "Duyet",
   "message": "Hé lô"
}

Response 200

{
   "status": "Success"
}

Response 400

{
   "status": "error"
}

GET /api/get_message

Response 200

[
   {
      "id": 1,
      "email": "me@duyet.net",
      "name": "Duyet",
      "message": "Hé lô"
   },
   {
      "id": 2,
      "email": "me@duyet.net",
      "name": "Duyet",
      "message": "xxx"
   },
   {
      "id": 3,
      "email": "me@duyet.net",
      "name": "Duyet",
      "message": "Hé lô"
   }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment