How does one set up multiple accounts with separate databases for Django on one server?

后端 未结 2 1329
心在旅途
心在旅途 2021-01-01 04:57

What options are there for installing Django such that multiple users (each with an \"Account\") can each have their own database?

The semantics are fairly intuitive

2条回答
  •  萌比男神i
    2021-01-01 05:24

    The Django way would definitely be to have separate installations with their own database name (#1). #2 would involve quite a bit of hacking with the ORM, and even then I'm not quite sure it's possible at all.

    But mind you, you don't need a WHOLE new installation of all the site's models/views/templates for each user, just a new settings.py with all the appropriate paths to the common source files. Plus, to run all these installations in Apache, do it the way I do here:

    
            DocumentRoot /www/site1
            ServerName site1.com
            
                    SetHandler python-program
                    SetEnv DJANGO_SETTINGS_MODULE site1.settings
                    PythonPath "['/www'] + sys.path"
                    PythonDebug On
                    PythonInterpreter site1
            
    
    
    
            DocumentRoot /www/site2
            ServerName site2.com
            
                    SetHandler python-program
                    SetEnv DJANGO_SETTINGS_MODULE site2.settings
                    PythonPath "['/www'] + sys.path"
                    PythonDebug On
                    PythonInterpreter site2
            
    
    

    assuming you've got /www/site1/settings.py, www/site2/settings.py and so on...

    Of course, you now need to have a main site where people log in, that then redirects you to the appropriate site (here I've just put it as "site1.com", "site2.com", but you get the idea.)

提交回复
热议问题