由用户创建的动态数据库 - django [英] dynamic databases created by users - django

查看:145
本文介绍了由用户创建的动态数据库 - django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个网站,用户可以登录并创建自己的数据库(也可以操作它们)。这些数据库将非常小,并且主要用于测试。阅读建议 解决方案 SO 看来我有几个选项:

I want to create a website where users can log in and create their own database (and also be able to manipulate them). These databases will be very small, and are ment to be used for testing mostly. Reading the suggested solutions here on SO it seems I have a few options:


  • 使用预定义的功能动态地将数据库添加到settings.py中(如在这里)。我发现这是一个非常糟糕的主意,因为它看起来像一个黑客,并暴露您自己的settings.py文件。

  • 将SQlite文件存储在媒体中,并连接给他们使用django.db.connections。这似乎是一个合理的解决方案,虽然我不知道如何执行它。

  • 不使用实际的数据库,但使用XML或其他格式存储信息,这可能会我的效率

  • 我自己的想法,这可能是疯狂的 - 将SQlite文件存储为MySQL数据库内的blob。

  • dynamically add database to settings.py using a pre-defined functionality (as suggested here). I find this to be a very bad idea since it seems like a hack and exposes your own settings.py file.
  • store SQlite files in media, and connect to them using django.db.connections. This seems like a reasonable solution, though I have no idea how to execute it.
  • don't use an actual database but an XML or some other format for storing information, which will probably cost me in efficiency
  • my own idea, which might be crazy stupid - store SQlite files as blobs inside MySQL database.

最终目标是允许用户在网站上创建django模型,然后对他们执行查询)。有任何想法吗?

The end-goal is to allow the users to create django models on the website and then perform queries on them (it's a learning website). Any ideas?

推荐答案

稍微超过伪代码,使用fabric:)

Slightly more than pseudocode, using fabric :)

from fabric import api

def django_start_project(project_name):
    api.run('mkproject %s' % project_name)  # Assumes you have virtualenvwrapper
    with api.prefix('workon %s' % project_name):
        api.run('pip install django')
        api.run('django-admin.py startproject')

最后一部分当然需要一些工作,但这是要点:)

The last part needs some work of course, but this is the gist :)

这样调用:

fab django_start_project:your_project

依赖关系:

  • Fabric: http://docs.fabfile.org/
  • Virtualenv: http://www.virtualenv.org/
  • Virtualenvwrapper: http://virtualenvwrapper.readthedocs.org/

这篇关于由用户创建的动态数据库 - django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆