简体   繁体   中英

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'} . I got that fixed through the first comment . The email got sent .But the link led to 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

  1. Six is deprecated in Django 3, you can use 'import six' instead of 'from django.utils import six'
  2. To send html email, add email.content_subtype = “html” after EmailMessage Object.
  3. activate url should be 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. Add your site name and domail in admin site (/admin/sites/site/) and replace SITE_ID with your sites pk.

But I did not understand how to set SITE_ID to my sites pk.

In settings.py set

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 . This is the important part to do.

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

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.

Hope, it will resolve your problem or issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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