Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用URL映射而不是域映射的多租户django应用程序_Python_Django_Url Routing_Multi Tenant_Pythonanywhere - Fatal编程技术网

Python 使用URL映射而不是域映射的多租户django应用程序

Python 使用URL映射而不是域映射的多租户django应用程序,python,django,url-routing,multi-tenant,pythonanywhere,Python,Django,Url Routing,Multi Tenant,Pythonanywhere,在django中,大多数多租户实现(模块)都将主机映射到视图上 e、 g.使用postgress模式映射主机/URL->django视图: customer1.myapp.com/view1/arg1 -> myapp.view1(arg1) using schema 'customer1' customer2.myapp.com/view1/arg1 -> myapp.view1(arg1) using schema 'customer2' customer3.myapp.co

在django中,大多数多租户实现(模块)都将主机映射到视图上

e、 g.使用postgress模式映射主机/URL->django视图:

customer1.myapp.com/view1/arg1 -> myapp.view1(arg1)  using schema 'customer1'
customer2.myapp.com/view1/arg1 -> myapp.view1(arg1)  using schema 'customer2'
customer3.myapp.com/view1/arg1 -> myapp.view1(arg1)  using schema 'customer3'
由于我的PaaS(Pythonywhere)不支持通配符域(*.myapp.com),我正在尝试使用URL映射设置多租户应用程序:

e、 g.映射URL->django视图:

myapp.com/customer1/view1/arg1 ->  myapp.view1(arg1) passing implicit parameter tenant='customer1'
myapp.com/customer2/view1/arg1 ->  myapp.view1(arg1) passing implicit parameter tenant='customer2'
myapp.com/customer3/view1/arg1 ->  myapp.view1(arg1) passing implicit parameter tenant='customer3'
在这里,一些中间件应该负责将租户参数传递给视图,并过滤适用于所选租户的对象的查询结果。 e、 g

但这里的问题是:对于URL映射而不是主机映射,如何做到这一点?哪个包可以处理这个问题

注意:django multitenants提到“支持url模式以及子域”,但不清楚如何做到这一点。。。

django multitenants
中进行了一番探索,它似乎是为了使用名为
TENANT\u BASE\u PATH的设置来支持基于URL的多租户


然而。。。如果选择,则文档中只会出现对该设置的引用,而不会出现在代码本身中。因此,
django multitenants
可能不是一个已完成的项目,而是一项可能已被放弃的正在进行的工作(上次提交仅在初始提交后14天)。

在Pythonywhere支持的大力帮助下,以以下方式解决了该问题:

  • 为每个租户创建一个新的webapp(是的,每月花费2美元)
  • 将新域映射到新的webapp(检查pythonanywhere web选项卡“DNS设置”)
  • 让每个webapp使用相同的代码和相同的postgres数据库(复制静态和媒体patsh以及wsgi脚本)
  • 在postgres数据库中创建新模式
  • 剩下的很简单:按照
  • 大致:

    • 同步新架构:./manage.py migrate\u schemas--schema=我的新租户
    • 将新租户添加到公用租户“customers\u client”表中
    • 如果您的用户模型不在公共表中:为此租户创建新管理员用户:./manage.py createsuperuser--schema=my new租户