开发者

Best practice: How to persist simple data without a database in django?

开发者 https://www.devze.com 2023-01-02 14:14 出处:网络
I\'m building a website that doesn\'t require a database because a REST API \"is the databas开发者_StackOverflow中文版e\". (Except you don\'t want to be putting site-specific things in there, since th

I'm building a website that doesn't require a database because a REST API "is the databas开发者_StackOverflow中文版e". (Except you don't want to be putting site-specific things in there, since the API is used by mostly mobile clients)

However there's a few things that normally would be put in a database, for example the "jobs" page. You have master list view, and the detail views for each job, and it should be easy to add new job entries. (not necessarily via a CMS, but that would be awesome)

e.g. example.com/careers/ and example.com/careers/77/

I could just hardcode this stuff in templates, but that's no DRY- you have to update the master template and the detail template every time.

What do you guys think? Maybe a YAML file? Or any better ideas? Thx


Why not still keep it in a database? Your remote REST store is all well and funky, but if you've got local data, there's nothing (unless there's spec saying so) to stop you storing some stuff in a local db. Doesn't have to be anything v glamorous - could be sqlite, or you could have some fun with redis, etc.


You could use the Memcachedb via the Django cache interface.

For example:

Set the cache backend as memcached in your django settings, but install/use memcachedb instead.

Django can't tell the difference between the two because the provide the same interface (at least last time I checked).

Memcachedb is persistent, safe for multithreaded django servers, and won't lose data during server restarts, but it's just a key value store. not a complete database.


Some alternatives built into the Python library are listed in the Data Persistence chapter of the documentation. Still another is JSON.

0

精彩评论

暂无评论...
验证码 换一张
取 消