I am creating a series of small sites, I'm using the django framework. The theory goes a user comes to a master site, signs up, then he gets his own child site.

Example:

  • navigate to example.com
  • user creates an account "mysite"
  • user then gets his own site: mysite.example.com and he can configure this all he wants

My question: * would it be better to have a "gold" version of the site that gets created for each site?

for instance: cp ~/goldsite ~/mysite and change the database pointers appropriately ** the downside is if I ever have to do maintenance on a file, I would have to change all subsites.

...or * have one host and configure the database to support multiple sites. The DB might get messy.

Any feedback would be great.

有帮助吗?

解决方案

My suggestion would be to create a separate django base server which will serve as a web service api.

This web server will use rpcdjango which, when used with any method as a decorator, converts it to a HTTP callable method.

You will have to put little more effort on database design so that it does not become too complex.

Then create your individual web application using any technology (I prefer AngularJS and Bootstrap) which will connect to the django server using Ajax methods.

Here is an example django rpc4django:

  1. First, you need to add a new URL pattern to your root urls.py file. You can replace r’^RPC2$’ with anything you like.

urls.py

urlpatterns = patterns(’’,
    # rpc4django will need to be in your Python path
    (r’^RPC2$’, ’rpc4django.views.serve_rpc_request’),
)
  1. Second, add rpc4django to the list of installed applications in your settings.py.

settings.py

INSTALLED_APPS = (
    ’rpc4django’,
)
  1. Lastly, you need to let rpc4django know which methods to make available. Rpc4django recursively imports all the apps in INSTALLED_APPS and makes any methods importable via __init__.py*** with the @rpcmethod decorator available as RPC methods. You can always write your RPC methods in another module and simply import it in __init__.py.

testapp/__init__.py

from rpc4django import rpcmethod
# The doc string supports reST if docutils is installed
@rpcmethod(name=’mynamespace.add’, signature=[’int’, ’int’, ’int’])
def add(a, b):
    ’’’Adds two numbers together
    >>> add(1, 2)
    3
    ’’’
    return a+b

rpc4django documentation

许可以下: CC-BY-SA归因
scroll top