哪里可以为Django Sites框架网站设置域名,当我只有一个? [英] Where do I set the domain for my Django Sites framework site, when I only have one?

查看:280
本文介绍了哪里可以为Django Sites框架网站设置域名,当我只有一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个简单的博客/论坛网站的Django项目。



我正在使用联合供稿框架,这似乎是使用当前站点的域从< a href =https://docs.djangoproject.com/en/dev/ref/contrib/sites/ =noreferrer>网站框架。


$ b $我以前不知道网站框架。我的项目不会用于多个网站,只有一个。



我想做的是设置当前网站的属性。在我的Django项目中应该怎么做?

解决方案

如果我理解正确,Sites框架数据存储在数据库中,所以如果我想要永久保存,我想这是适当的在 initial_data fixture



我启动了Django shell,并执行了以下操作:

 >>>来自django.contrib.sites.models import Site 
>>> one = Site.objects.all()[0]
>>> one.domain ='myveryspecialdomain.com'
>>> one.name ='我的特殊网站名称'
>>> one.save()

然后我在命令行中抓取了这些数据:

  python manage.py dumpdata sites 

并将其粘贴到我先前存在的 initial_data 夹具中。


I have a Django project for a simple blog/forum website I’m building.

I’m using the syndication feed framework, which seems to generate the URLs for items in the feed using the domain of the current site from the Sites framework.

I was previously unaware of the Sites framework. My project isn’t going to be used for multiple sites, just one.

What I want to do is set the domain property of the current site. Where in my Django project should I do that? Somewhere in /settings.py?

解决方案

If I understand correctly, Sites framework data is stored in the database, so if I want to store this permanently, I guess it’s appropriate in an initial_data fixture.

I fired up the Django shell, and did the following:

>>> from django.contrib.sites.models import Site
>>> one = Site.objects.all()[0]
>>> one.domain = 'myveryspecialdomain.com'
>>> one.name = 'My Special Site Name'
>>> one.save()

I then grabbed just this data at the command line:

python manage.py dumpdata sites

And pasted it into my pre-existing initial_data fixture.

这篇关于哪里可以为Django Sites框架网站设置域名,当我只有一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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