django - 将默认 Django 站点名称和域从 example.com 更改为正确的

标签 django django-models django-sites

根据 Django 文档 (here):

django.contrib.sites registers a post_migrate signal handler which creates a default site named example.com with the domain example.com. This site will also be created after Django creates the test database. To set the correct name and domain for your project, you can use a data migration.

直接从 Django 管理面板更改默认值不是安全吗?为什么?

最佳答案

这是我的回答。 第一个选项是在 Django 管理站点上更改它们。 第二个选项是手动创建迁移文件并运行迁移。 让我在这里描述第二个选项。 首先,使用以下命令创建一个空迁移。

$ python manage.py makemigrations --empty --name update_site_name app_name

接下来引用这个blog编辑迁移文件。

最后,运行迁移。

谢谢。

关于django - 将默认 Django 站点名称和域从 example.com 更改为正确的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65733649/

相关文章:

django - 你如何为 Django ForeignKey 字段指定默认值?

Django - 多站点站点缓存

Django:在创建对象时搜索多对多字段

django - 为什么我无法在 ModelForm 的 save() 函数中设置 OneToOneField?

django - 当我只有一个域时,我应该在哪里为我的 Django Sites 框架站点设置域?

django - django 中 SITE_ID 设置的用途是什么?

django - 从 pre_save 接收器函数引发 ValidationError?

python - 在 Django 中隐藏日期时间模型字段中的时间?

javascript - 将 tastypie 过滤器与 AngularJS 和 RESTANGAL 一起使用

javascript - 在 JS 脚本中使用 Django 模板标签可以吗