简体   繁体   English

DJANGO:将site_id 设置为sites pk

[英]DJANGO: Set site_id to sites pk

I am following this tutorial for email verification.The version the author is working with is old.I got an error that said Reverse for 'activate' with keyword arguments '{'uidb64': b'OA', 'token': '4tm-3fcfb375c8ba14f9a95b'} .我正在关注本教程进行电子邮件验证。作者正在使用的版本是旧版本。我收到一个错误,提示Reverse for 'activate' with keyword arguments '{'uidb64': b'OA', 'token': '4tm-3fcfb375c8ba14f9a95b'} I got that fixed through the first comment .我通过第一条评论解决了这个问题。 The email got sent .But the link led to www.example.com .电子邮件已发送。但链接指向www.example.com The second comment tells how to fix that .第二条评论告诉了如何解决这个问题。 The comment was : For those are using Django 3, You should change some code评论是:对于那些使用 Django 3 的人,你应该更改一些代码

  1. Six is deprecated in Django 3, you can use 'import six' instead of 'from django.utils import six' Django 3 中不推荐使用六,您可以使用“导入六”而不是“从 django.utils 导入六”
  2. To send html email, add email.content_subtype = “html” after EmailMessage Object.要发送 html 电子邮件,请在 EmailMessage 对象后添加 email.content_subtype = “html”。
  3. activate url should be path('activate//', views.activate, name='activate'),激活 url 应该是 path('activate//', views.activate, name='activate'),
  4. get_current_site(request) will return example.com as default when SITE_ID=1 in your settings.py.当您的 settings.py 中的 SITE_ID=1 时,get_current_site(request) 将默认返回 example.com。 Add your site name and domail in admin site (/admin/sites/site/) and replace SITE_ID with your sites pk.在管理站点 (/admin/sites/site/) 中添加您的站点名称和 domail,并将 SITE_ID 替换为您的站点 pk。

But I did not understand how to set SITE_ID to my sites pk.但我不明白如何将 SITE_ID 设置为我的网站 pk。

In settings.py setsettings.py设置

BASE_URL = 'https://www.yourdomainname.com'

Don't include trailing / Also, you have to mention this line in the same file不要包括尾随/另外,你必须在同一个文件中提到这一行

SITE_ID = 1

Moreover, go to your django admin pannel , default is /admin , and go to the sites tab/model and add/edit your site according to your ip/domainName and display name .此外,转到您的django admin面板,默认为/admin ,然后转到sites选项卡/模型并根据您的ip/domainNamedisplay name添加/编辑您的site This is the important part to do.这是要做的important part

If you are testing locally for now then you can use 127.0.0.1:8000 in your ip/domainName and yourdomainNAme.com in display name如果您现在在本地进行测试,那么您可以在ip/domainName使用127.0.0.1:8000 ,在display name yourdomainNAme.com

If you are deploying or using live then you can use actual ip of your server into ip/domainname or also you can use your domain name (as it's mapped to your ip via DNS system) and display name will be the same.如果您正在部署或使用实时,那么您可以将服务器的实际 ip 使用到ip/domainname或者您也可以使用您的域名(因为它通过 DNS 系统映射到您的 ip)并且显示名称将相同。

Hope, it will resolve your problem or issue.希望,它会解决您的问题或问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM