我在 pythonanywhere 工作并且我已经运行了一个注册脚本 - 本地它在 pythonanywhere 中没有问题我得到这个错误
2020-09-13 15:37:43,507: Internal Server Error: /signup1/
Traceback (most recent call last):
File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/username/werkvertragrepo/werkvertrag/views.py", line 612, in signup1
text_body = render_to_string('acc_active_email.txt', merge_data)
File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/template/loader.py", line 62, in render_to_string
return template.render(context, request)
File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/template/base.py", line 170, in render
return self._render(context)
File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/template/base.py", line 162, in _render
return self.nodelist.render(context)
File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/template/base.py", line 938, in render
bit = node.render_annotated(context)
File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/template/base.py", line 905, in render_annotated
return self.render(context)
File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/template/defaulttags.py", line 446, in render
url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/urls/base.py", line 87, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/urls/resolvers.py", line 685, in _reverse_with_prefix
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'activate' with keyword arguments
'{'uidb64': 'NTA', 'token': 'aa5a2v-c248dcaea908540be1e8e3d5feff970f1'}' not found. 1
pattern(s) tried: ['activate/(?P<uidb64>[0-9A-Za-z_\\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-
Za-z]{1,20})/']
服务器日志
2020-09-13 15:37:43 {'user': <User: user@usermail.de>, 'domain': 'www.mywebsite.de',
'uid': 'NTA', 'token': 'aa5a2v-c248dcaea908540be1e8e3d5feff970f1'}
2020-09-13 15:37:43 Internal Server Error: /signup1/#012Traceback (most recent call l
ast):#012 File "/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/core/handlers/exception.py", line 47, in inner#012 response =
get_response(request)#012 File
"/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/core/handlers/base.py", line 179, in _get_response#012 response =
wrapped_callback(request, *callback_args, **callback_kwargs)#012 File
"/home/username/werkvertragrepo/werkvertrag/views.py", line 612, in signup1#012 text_body
= render_to_string('acc_active_email.txt', merge_data)#012 File
"/home/username/.virtualenvs/myenv/lib/python3.6/site-packages/django/template/loader.py",
line 62, in render_to_string#012 return template.render(context, request)#012 File
"/home/username/.virtualenvs/myenv/lib/python3.6/site-
packages/django/template/backends/django.py", line 61, in render#012 return self.template
如果发现错误出现在此行的视图中:
text_body = render_to_string('acc_active_email.txt', merge_data)
在我的本地主机上它可以正常工作
视图.py
def signup1(request):
if request.method == 'POST':
form = werkforms.UserCreationform(request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
email = form.cleaned_data.get('email')
raw_password = form.cleaned_data.get('password1')
Firmennamen = form.cleaned_data.get('Firmennamen')
Street = form.cleaned_data.get('Street')
plzort = form.cleaned_data.get('plzort')
user = User.objects.create_user(username, email, raw_password)
user.is_active = False
user.save()
userid = user.id
UserID = User.objects.get(id=userid)
current_site = get_current_site(request)
print("hallo")
merge_data = {
'user': user,
'domain': current_site.domain,
'uid': force_text(urlsafe_base64_encode(force_bytes(user.pk))),
'token': account_activation_token.make_token(user),
}
print(merge_data)
text_body = render_to_string('acc_active_email.txt', merge_data)
--- some more code ---
test = "das ist response"
return HttpResponse(test, content_type="text/html")
acc_active_email.txt
Hallo {{ user }},
Willkomen beim Onlineforum,
Deine Registrierung war erfolgreich. Klicke nun auf den unteren Link um deine Registrierung abzuschließen.
http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
Vielen Dank
Mit freundlichen Grüßen