动态子导航(Dynamic sub nav)
我为自己创建了一个投资组合网站,有一个用户可以进入的图库,点击缩略图然后转到一个新的html页面,其中包含完整的图像和描述。 现在在这个完整的图像页面上,我有一个项目2,3,4,5等的其他全图页面列表。
但显然手动更新project2.html以获得子导航中的所有其他项目minius项目2的列表非常繁琐,当我必须为所有12个页面执行此操作时将出现错误。 因此,在人们观看的页面之后我不会出现在该子导航中。
我的问题是..我是否废弃自定义html网站并转移到cms ..这种动态导航的逻辑步骤。 或者如果可能的话我尝试包含php。 任何人都可以建议最好的方法,我知道它可能在longrun更容易运行cms但我喜欢控制我得到和知识我手工制作我的HTML。
谢谢你
Ive created a portfolio website for myself, there is a gallery which users can enter, click on a thumbnail and then go to a new html page with the full image and description. Now on this full image page i have a list of other fullimage pages for project 2,3,4,5, etc..
But obviously manually updating project2.html to have a list of all other projects minius project 2 in the sub nav is very tedious and mistakes will occus when i have to do it for all 12 plus pages. So im after the page people are viewing not to appear in that sub nav.
My problem is.. Do i scrap the custom html site and move onto a cms.. The logical step for this sort of dynamic nav. Or do i try and include php if possible. Can anyone suggest the best approach for this, im aware it might in the longrun be easier to run off a cms but i do like the control i get and knowledge i hand crafted my html.
Thanks Mat
原文:https://stackoverflow.com/questions/9177060
最满意答案
在django文档中的multi-db(手动选择数据库)
# This will run on the 'default' database. Author.objects.all() # So will this. Author.objects.using('default').all() # This will run on the 'other' database. Author.objects.using('other').all() The 'default' and 'other' are aliases for you databases. In your case it would could be 'default' and 'remote'.
当然你可以用你想要的任何东西替换.all()。
Example: System.objects.using('remote').get(id=123456)
In the django documentation multi-db (manually-selecting-a-database)
# This will run on the 'default' database. Author.objects.all() # So will this. Author.objects.using('default').all() # This will run on the 'other' database. Author.objects.using('other').all() The 'default' and 'other' are aliases for you databases. In your case it would could be 'default' and 'remote'.
of course you could replace the .all() with anything you want.
Example: System.objects.using('remote').get(id=123456)
相关问答
更多-
在Django模型,sqlite和mongoengine中管理数据库(Managing databases in Django models, sqlite and mongoengine)[2021-09-07]
这可以帮助你: 我完全同意使用数据库路由器。 我所做的是,我用单一的管理界面来处理多个数据库。 请注意,所有应用程序的身份验证都存储在默认数据库中。 Settings.py # Define the database manager to setup the various projects DATABASE_ROUTERS = ['manager.router.DatabaseAppsRouter'] DATABASE_APPS_MAPPING = {'app1': 'db1', ... -
您有一个语法错误,因为您缺少一个逗号: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'testdatabase', 'USER': 'root', 'PASSWORD': 'Xma47data', 'HOST': 'localhost', 'PORT': '3306', }, # <-- HERE 'vnosdatabase': { 'ENG ...
-
您需要在settings.py定义两个数据库。 您应该阅读设置多个数据库文档 。 这很直接。 配置和同步数据库后,可以手动为QuerySet选择数据库,如下所示: Model.objects.using('database').all() 更新: 要为模型指定连接,可以按如下方式定义Router 。 from django.db import connections class MyRouter(object): """ This router object will take care ...
-
Django和多个数据库(Django and multiple databases)[2022-06-28]
Django Project正致力于多数据库支持 。 最近还有一篇(2009年11月10日)关于“MultiDB状态(在Django中)”的博客文章。 更新:自Django v1.2 (2010年5月发布)以来支持多个数据库 。 Django Project is working on Multiple Database Support. There is also a recent (Nov 10 2009) blog post about "The state of MultiDB (in Django ... -
正如评论中所发现的 - 这是一篇描述如何设置服务器实例并随时选择数据库的文章,因此其作者应该获得所有学分。 重申基本方法: 创建表示数据库连接的模型类: class Database(models.Model): name = models.CharField(max_length=256, unique=True) config = JSONField() 添加label属性以区分db连接实体。 这里,它需要在django设置中设置字符串DYNAMIC_DATABASES_PREFIX和 ...
-
您如何存储它们取决于您需要如何查询它们。 例如,如果您只需要查找父项的直接子项,则邻接列表模型可能是最简单的。 如果你想枚举整个子树,祖先列表或嵌套集合运行良好 - 尽管我会避免App Engine上的嵌套集合。 如果您需要树中所有对象的事务完整性 - 并且不会每秒更新一次,那么您应该查看App Engine对实体组和祖先的支持。 How you store them depends on how you need to query them. For example, if you only need t ...
-
您的问题实际上并不清楚您的实际期望,但无论如何,这里有一些提示: 首先,模型实例(假设它们是相同模型的实例)比较它们的主键值,该键值也用作字典和集合的哈希值,因此如果要比较基础数据库记录,则不应使用模型实例,但将原始数据库值视为元组或列表的列表。 您可以使用(或) Queryset.values_list()或Queryset.values()来获得这些内容 - 不要忘记list()它们,以便您真正获得list而不是查询集。 这将我们带到了第二个重要的地方:虽然将自己呈现为列表类(在它们支持len() ,迭 ...
-
Django 支持多个数据库 。 你可以保留你的scraping程序/数据库,并直接通过Django访问数据库。 像平常一样设置模型 - 但在META字段中设置managed = False 。 这将阻止Django将迁移应用到数据库。 如果您发现您确实想通过Django模型管理数据库,则需要设置一个路由类,以确保您的应用只针对预期的数据库。 Django supports multiple databases. You can leave your scraping program/database as ...
-
在django文档中的multi-db(手动选择数据库) # This will run on the 'default' database. Author.objects.all() # So will this. Author.objects.using('default').all() # This will run on the 'other' database. Author.objects.using('other').all() The 'default' and 'other' are ...
-
最后我设法解决了这个问题。 我使用创建表 manage.py syncdb --all manage.py migrate --fake 由于完整性问题,使用loaddata加载转储不起作用。 (例如,破坏外键约束) 所以我不得不改变我的桌子。 我删除了破坏的约束,然后我可以毫无问题地运行loaddata 。 但是,当然我的数据库仍然被打破,因为我放弃了一些约束。 因此,我只需要使用psql shell再次更改我的表。 pgAdmin派上用场,因为在用户友好的界面上显示相关的转储查询,分别针对每个不同的约 ...