我在创建帐户并使用电子邮件中发送的链接激活帐户时遇到问题。该应用程序是用 Django 2.2 版本编写的。
单击激活链接后,我收到一条消息:
Reverse for 'activate' with keyword arguments '{'uidb64': '', 'token': ''}' not found. 1 pattern(s) tried: ['activate/(?P<uidb64>[^/]+)/(?P<token>[^/]+)/$']
urls.py 中的代码
path('activate/<uidb64>/<token>/', account.activate, name='activate'),
代码在views.py中,注册和激活链接的代码。注册就像 CBV,激活就像 FBV。
class Signup(View):
def get(self, request):
form = SignUpForm()
return render(request, 'account/signup.html', {'form': form})
def post(self, request):
form = SignUpForm(request.POST)
if form.is_valid():
user = form.save(commit=False)
user.is_active = False
user.save()
current_site = get_current_site(request)
subject = 'Activate your Spotted account'
message = render_to_string('account/account_activation_email.html', {
'user': user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user)
})
user.email_user(subject, …Run Code Online (Sandbox Code Playgroud) 我在 django 2.2 中运行命令时遇到问题。该应用程序在INSTALLED_APPS. 我收到一条消息:
Unknown command: 'my_command'
Type 'manage.py help' for usage.
Run Code Online (Sandbox Code Playgroud)
下面是项目的结构:
project/
app/
managment/
commands/
my_command.py
models.py
views.py
...
Run Code Online (Sandbox Code Playgroud)
my_command.py
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'My custom command'
def handle(self, *args, **options):
code here
Run Code Online (Sandbox Code Playgroud)