pythome.com (Flask)
The Python error guide pythome.com, rewritten with Flask.
This repository contains a version of pythome.com, the site that collects Python error messages, rewritten with Flask. I had written the first version of the site with Django and Jinja2. In April 2016, within a few days, I moved the same site to Flask to give it a smaller structure that was easier to manage. In this version I also added translations, comments and a browser extension next to the error records. The code is shared under the MIT licence.
Purpose
Because the error messages on pythome.com were collected from library source code, they were in English. My real goal was to also explain in Turkish what these messages mean. That required a structure where records could be translated and readers could leave comments. I felt that the settings and app structure of the Django version were too much for such a small site. A Flask application kept in a single file was simpler both to read and to run on the server.
How it works
All of the application's routes are defined in ilk.py. The home page lists the records in the Hatalar table and puts the ones with a Turkish translation first. The search box suggests error messages with jQuery Easy Autocomplete, while the /ara/?q= address searches for a phrase inside the messages. Detail pages use the same /module/error-type/message/ address structure as the first version, so addresses that had already been indexed did not change. Below each detail page, other errors of the same type are listed and a Disqus comment area is shown.
For translations I added sign-in with GitHub. When a visitor signs in with their GitHub account, a marker is written to the session and the /cevir/ page becomes available. On that page the Turkish, German and Hindi equivalents of an error message can be entered; submitting the form updates the record. Anyone who tries to open the translation page without signing in is redirected to the home page.
The repository also contains a small Chrome extension called ekle.crx. It adds a "Solve this error." option to the right-click menu. When you select an error message on any page and click that option, the selected text opens in a new tab on pythome.com's search address.
Highlights
- Queries are parameterised, so search text coming from the user is never inserted directly into SQL.
- The home page and detail pages are cached briefly with memcached.
- Error records have translation fields for Turkish, German and Hindi.
- Translating is open only to users who sign in with GitHub.
- The Chrome extension searches the site for an error message on any page with a single click.
Technical background
The application runs on Flask and connects to MySQL with MySQLdb. I used the Flask-GitHub extension for GitHub sign-in. An ilk.wsgi file is ready for running it on the server with Apache mod_wsgi. The interface is built with Bootstrap and jQuery, and the robots.txt and sitemap.xml files are also served from the root address through Flask.
- Category
- Websites
- Year
- 2016
Technologies
- Python
- Flask
Links
- GitHub https://github.com/muslu/pythome.com_flask