为两个具有不同样式表和模板但具有类似Django后端的网站的最佳做法设置 [英] Best practice setup for two websites with different style sheets and templates, but similar Django back end

查看:64
本文介绍了为两个具有不同样式表和模板但具有类似Django后端的网站的最佳做法设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Django后端,该后端将由两个网站(即,非营利组织的工作委员会和营利性公司的工作委员会)使用,但是我不确定这是最好的方法其结构使其可以轻松地将更新推/拉到这两个网站.

I'm working on a Django back end that will be used by two websites (i.e., a job board for non-profits and a job board for for-profit companies), but I'm not sure how this is best structured to make it easy to push/pull updates to the two websites.

网站的Django代码非常相似(例如重叠率超过95%),但是网站的模板和CSS样式表略有不同,以便为每个网站提供独特的外观和感觉.

The Django code for the websites is highly similar (let's say over 95% overlap), but the websites have slightly different templates and separate CSS style sheets, in order to give each a distinct look and feel.

我的意愿是将其设置为单个Django项目,该项目存储两个网站的CSS样式表,每个网站都有一个不同的template文件夹,并具有多个设置文件(例如base,production_fprofit,production_nprofit).为了促进后端的任何当前或将来差异,设置变量将指示使用该代码的平台(例如, FPROFIT = True/FPROFIT = False ),并在必要时调用此变量(例如, if settings.FPROFIT == True:payment_required()).每当Django代码更改时,代码就会被两个平台推送到GIT并由它们拉出-每个平台都运行在单独的虚拟主机上,并具有自己的测试,登台和生产环境.

My inclination would be to set this up as a single Django project that stores the CSS style sheets for both websites, has a different templates folder for each website, and has multiple settings files (e.g., base, production_fprofit, production_nprofit). To facilitate any current or future differences in the back end, a settings variable would indicate the platform for which the code is used (e.g., FPROFIT = True/FPROFIT = False) and this variable is called when necessary (e.g., if settings.FPROFIT == True: payment_required()). Whenever the Django code changes, the code is pushed to GIT and pulled by the two platforms - each running on a separate virtual host, with their own testing, staging, and production environments.

我可以看到的两个主要选择包括将项目分开,但共享应用程序(不确定版本控制/GIT的工作方式)或分叉"项目并像这样更新master分支:

The two main alternatives that I can see include keeping the projects separate, but sharing the apps (not sure how this works with version control/GIT) or "forking" the project and updating the master branch like so:

更新分叉的GitHub存储库以匹配原始的最新代码和提交

尽管我的方法(即一个项目,单独的样式表和模板)对我来说似乎最简单,但感觉并不像GITonic/Djangothonic/Pythonic.我担心我选择此解决方案是基于我缺乏应用程序部署或在GIT中使用fork的经验,我会遇到很多问题.因此,我很想听听您的想法和经验.

Although my approach (i.e., one project, separate style sheets and templates) seems the most straightforward to me, it does not feel very GITonic/Djangothonic/Pythonic. I'm concerned that my choice for this solution is based on my lack of experience with the deployment of apps or working with forks in GIT and that I will run into issues down the line. Therefore, I am keen to hear your thoughts and experiences.

推荐答案

在我不得不部署两个具有不同模板但大多数情况下具有相同后端的不同Web应用程序(遇到几行不同的情况)后,我遇到了类似情况代码).

I ran into a similar situation once where I had to deploy two different web applications with different templates but the same backend for the most part (a few lines of different code here and there).

这是我遵循的方法:

  1. 主仓库
    它包含所有Django/Python代码.所有主要的发展都发生在这个仓库中.它还具有一些准系统模板和基本样式表.所有错误也已在此处修复.
  2. 克隆存储库
    这些存储库是 Main repo 的克隆.每次需要部署新应用程序时,只需为其创建一个副本.
    您可以在自己的存储库中实现特定于该Webapp实例的新功能,例如模型中的额外字段,视图中的额外行或更改模板和样式表.
  1. Main repo
    It contains all the Django/Python code. And all the main development happens in this repo. It also has some barebones templates and basic stylesheet. All the bugs are also fixed here.
  2. Clone repos
    These repos are clones of the Main repo. Every time you need to deploy a new application, you just create a clone for it.
    You implement new features that are specific to a particular instance of the webapp in it's own repo, for example extra fields in a model, extra lines in a view, or changing the templates and stylesheets.


工作流程:

  1. 主仓库中创建核心应用.
  2. 对于 N-Profit 网络应用,请克隆 Main repo .
  3. 更新 N-Profit 代码(例如样式表)和设置(例如 FPROFIT = False 等)
  4. 部署 N-Profit .
  5. 对于 F-Profit ,克隆 Main repo .
  6. 更新代码,例如 FPROFIT = True
  7. 部署 F-Profit .
  1. Create the core app in the Main repo.
  2. For N-Profit webapp, clone the Main repo.
  3. Update the N-Profit code, like the stylesheets, and settings like FPROFIT = False, etc.
  4. Deploy N-Profit.
  5. For F-Profit, clone the Main repo.
  6. Update code, like FPROFIT = True, etc.
  7. Deploy F-Profit.

您可以在 Main repo 中实现所有Web应用程序共有的新功能,然后从此处提取新更改.

You can implement new features that are common to all your webapps in the Main repo and then pull the new changes from here.

这篇关于为两个具有不同样式表和模板但具有类似Django后端的网站的最佳做法设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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