Flask Instance-Note application Qotes

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

This article is the 12th article of the "Crawling Python" series.

Originally intended to week more, pigeons for several weeks. The reason is that the object-oriented one is a bit difficult to write, and the other is I went to get a Web project-qotes. Before the book and the experimental building online class tried several times flask, this is the real actual combat.

The experience is good.

So the topic said that the crawler, the results of the first major practice is the Web project combat. In this paper, even before the introduction of the flask framework to give an example, in the future according to this example to expand the details of it.

Qotes Development Intention

Then post the link qotes.

In fact, the development of the project was originally written in the website. I originally wrote this topic in Jane to tidy up the knowledge, because the markdown editor of Jane's book is very useful. But I later found a problem, Jane book to take the note-type application of the document management, is a notebook can be added to an article of the note, but the note can not add notes, and can not be in the notebook to create a note book. This has caused me a lot of trouble.


Let me explain where I am troubled.

    • Can see my collection of novels in the text and set two parts, if you can put these two collections in a folder "novel" is not the same as the other corpus logic above, but this cannot be done, unless I set a series of articles in the novel mixed in the head or tail of the text of the novel.
    • There are also problems within the anthology. For example, "Diary" is some of my messy and fragmented notes at any time. But a single structure makes it difficult to organize these notes. For example, "MongoDB tips" In fact, this can be divided into several articles, but if separate, then and the other articles in the anthology logic inconsistent.

Summed up is: 1 anthology cannot contain 2 articles cannot contain.

I thought about other options later. The best thing about this is this: Write your study notes on GitHub with Typora.

But always feel a bit overqualified, and GitHub open speed is not ideal (most of the time normal, sometimes to 2s or so, it is difficult to suffer), the bigger problem is that GitHub's private repository need to charge, the fee is not convenient. GitHub pages, which function more in line with this scenario, are not as good as the walls. So I decided to use Jane's book. It was still a bit uncomfortable.

Then I thought I'd write one myself. So I tried to write it.

Features of Qotes

Card

The first thing to solve is the inclusion of articles and essays. Finally, my solution is this:

    • All the notes are in the form of cards.
    • All cards have the same status in the database and are stored in the same collection
    • Cards can contain each other, each card does not necessarily have a child card, but there must be a parent node.
    • If the parent node is a user, then the card can be considered a card set
    • Of course, each card can be seen as a set of sub-cards for a set of cards.

To sum up, each card is both a card and a card set.

In the database equivalent is like a tree node in memory scattered but through the link to form a tree structure, the only difference is that the root node is sometimes the user, and the tree structure is generally linked to record the child node information, but in this case the card through the parent node information to complete the structure of the link. The reasons for this are:

    • To make the query easier, the query speed is faster (theoretically) than one query based on the IDs in the child nodes table of a node after the index is set for the related fields.
    • To simplify IO operations. There can be only one parent node per node, but there may be many child nodes. If the record child node information to operate on the list, and the card belongs to the relationship between the new and old parent node two cards, the current logic only need to change the card's parent node information can be.

This also poses some problems. For example, a card cannot belong to more than one card, but the traditional tree structure I refer to does not support a child node with multiple parent nodes. I later in the development process thought, the overall idea and the Linux file system all the files are similar to the design, but there are some differences in the way of implementation.

More implementation details will be analyzed in a later article.

Markdown

Another feature is the markdown. First of all, the language is basically more than simple books, but not as GFM. The principle of course is to keep the spirit of markdown and quickly build the document structure with plain text. So the title of the card is directly in the card content # title , level two title h2 and ## subtitle as a summary of the card content. These basic contents are used as information in the preview of the card.


For example, when the card editor does not have to write the title, the title and summary will be generated automatically.


said that the text of the book needs a title, the article can be used in fact troubled me for a long time. If you do not write, the article content does not have a level header directly with the two-level title is not in accordance with the markdown specification, but if written, from the Web page to see the article has two titles are actually not in line with the HTML specification. The problem is that the file name does not exist in the markdown file, so the markdown file can be filled in exactly with the markdown specification and given only one level title.

You also don't laugh at my pedantic, the HTML specification changed to HTML5 after the emphasis on HTML is only responsible for content grading, the layout and format to the CSS and JS to do. In fact, this is the spirit, and markdown and HTML is the same markup language, old-timers are learning progress, emulate should be.

Also worth saying is the homepage of the fast editing mode.


The one on the right is an editor. Yes, in addition to the input content and the submit button nothing, real-time input, real-time conversion into HTML preview, and Typora similar. This is actually the spirit of markdown, simplifying the input while completing the format.

Technology selection

Back end, for rapid development, selected flask. To facilitate iterations, the database chooses MongoDB. Of course, there are other reasons, such as I am more familiar with flask, I would like to try NoSQL.

Front end nothing to say, Bootstrap is my savior. In the middle of the day, JavaScript and jquery wrote a few simple interactions. Both markdown editors are open source editors from GitHub, and to be honest, the time to find these two editors is longer than when I wrote the first few scripts I mentioned earlier.

In fact, I have to consider the rest of the API after writing, the front-end to Ajax, UI optimization, you may use Golang to re-write the project again. For the time being, flask is completely enough to support the business, although did not do stress testing, but I set the maximum number of simultaneous connections only 1000, not out of the code too large accident is certainly enough to cope with. This is not my own technical self-confidence, is MongoDB is too strong. I want to refactor the code but I want to try Golang experience.

In fact, the choice of MongoDB is my whim of the decision. Flask MongoDB External Library ODM not a good, really heart tired, may be I was sqlalchemy and flask-sqlalchemy spoil it. In short I later directly with Pymongo to write a simple mapping, the code may not be too good-looking but the effect can also be changed in the middle of the time to find that the iteration is very ideal. Here is a pymongo of the document, is a model, too envious, I have seen in addition to pythonhowtos experience the best documents. I'm going to look at it now, and if MySQL doesn't work better for my data structure design, development might be more cumbersome.

Some of the current pits

The private card hasn't been done yet. This is my most urgent todo at the moment.

Because of the relationship between the record, I simply shut down the communication between the user interface to avoid risk, the design is that the average user can only create their own cards, can only browse their own and my card. This basically calculates the best use of the personal blog can do business. Users can use it as a gadget, but it is a personal blog for the record-keeping nature, without crossing the border.

The focus function is simply shelved, and the comment function is not intended to be done from the outset. Other people's notes, even the public, but not the BB. Of course, if you want to experience a more complete function can also send mail to me, mailbox to the site to find it, posted here afraid of being crawled to a heap of junk mail. The anti-climb of the book is too chicken, limit the amount of practice is a bit self-deception.

Uppercase and bold mobile experiences are poor. This is actually not too big a problem for me. I've never used a simple book app to edit an article because the SE screen is too small. And as a few years of WP users, I have been accustomed to use the phone to complete the phone, text messages and watch the news, weather features (I really do not in the black Windowphone). The computer completes the work to be more convenient, the handset code cannot code, my mobile phone on the other hand does not use the simple book, OneNote also is not commonly used. Before using WP also use, iOS OneNote is simply stupid, rather than turn on the computer operation.

But I think about it, it's not a problem for me but it doesn't apply to other people. Although Bootstrap on the mobile side of the display has tried, but I write the main interactive way to drag and drop in the mobile browser is really difficult to play a useful, can only hope when I can be like a worker who will be happy to make an app.

So this article actually has little relation with flask

That's not true. This article is just a first introduction to the practice project. There is a lot of experience in the middle that is worth exchanging. The collaborative work of Flask and MongoDB is worth telling, and the various pits in application deployment are worth sharing. For example, Ali from August this year began to ban ECS out of port 25 wasted me a lot of time to troubleshoot problems. For example, how uncomfortable it is for CentOS to install supervisor with Yum, such as Flask-wtform wtforms and Flask-bootstrap quick_form. As for the bald Brother Flask Web Development in the book of the various times pits will not talk about.

Link

    1. qotes
    2. Other updates related to the technical articles, and then write it according to different content.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.