简体   繁体   中英

Using Python and flat file database for server-side

I don't have access PHP server nor database like Mysql on machine I'll be working on. Would it be feasible to use Python instead of PHP and flat file database instead of Mysql? I'm not too concerned about performance or scalability. It's not like I'm going to create next facebook. I just want to load data from server and show it on webpage and possibly handle some input forms. Also is there any major flaw with my reasoning? Or is there any other way to circumvent lack of PHP and database on server?

Using Python on a server is a longer story, because Python and PHP are not comparable. Have a look at Python + Django, and then think of what you want to do. See: https://www.djangoproject.com

Writing server-side scripts with Python is not difficult, and the WSGI interface works well. However, you usually need several layers of software if you want to get PHP-equivalent functionality.

The second question - database - is easier. Python comes with SQLite3 interface, so there you have a quite-SQLish database with only a single DB file. SQLite is very widely used and usually reliable. For more information on the sqlite3 modeule, see: https://docs.python.org/2/library/sqlite3.html .

Python comes bundled with sqlite3 module that gives access to SQLite databases. The only downside is that it is pretty much possible for just one thread can have write locks to it at any given moment.

There are many ways to serve Python applications, but you should probably look at something that does this using the WSGI standard. Many frameworks will let you do this eg: Pyramid, Pylons, Django, ..... If you haven't picked one then it would be worth looking at your long term requirements and also what you already know.

In terms of DB, there are many choices. SQLlite has been mentioned, but there are many other DBs that don't require a server process. If you're only storing a small amount of data then flat files may work for you, but anything bigger or more relational, then look at SQLlite.

If you're looking to get into Python for web development, take a look at the Flask framework.

There are numerous examples where a flat file is used to serve data, rather than a database.

See the blog post by James Sharding which discusses how to use Flask-FlatPages to serve content from files.

You can easily adapt this to serve straight text (rather than parse it as Markdown), as well.

The end result is a lean, robust system that avoids the overhead of a database.

As the other answers suggest, using SQLite is another great option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM