How to fix invalid literal for int() with base 10: '{tno'?

When I use django with redirect(‘some uell’), error occurs:

invalid literal for int() with base 10: ‘{tno’


.
Not only redirect will be errored, but reverse also be this.

Can anyone tell me how to fix it ?

un = request.POST.get("email", '')
        pwd = request.POST.get("password", '')
        rpwd = request.POST.get("passwordx", '')
        if not un or not pwd or not rpwd:
            messages.error(request, '输入的用户邮箱、密码无效。请重新输入。')
            request.session['hint'] = {"email": un}
            return redirect('/signup.html')

        if pwd != rpwd:
            messages.error(request, '两次输入的用户密码不一致。请重新输入。')
            request.session['hint'] = {"email": un}
            return redirect('/signup.html')

        user = User.objects.filter(username=un)
        if user:
            messages.error(request, '用户已存在。请重新输入。')
            request.session['hint'] = {"email": un}
            return redirect('/signup.html')
        else:
            emailed = AccountService.sendverify(un, pwd)

Welcome @zwjat !

We’re going to need to see more details about this issue.

Please post the complete view, the complete error and traceback from your runserver console, and the template being rendered by the view throwing this error.

Thue urls.py

from django.urls import re_path

from . import views
from .views import profile, manage

urlpatterns = [
	re_path('signin.html', profile.signin, name='signin'),
	re_path('signup.html', profile.signup, name='signup'),
	re_path('signout.html', profile.signout, name='signout'),
]

The views

from django.shortcuts import render, redirect, HttpResponse
from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.contrib.auth import login, logout, authenticate
from django.contrib.auth.hashers import make_password
from django.contrib import messages
from django.conf import settings
def signup(request):
    '''注册
    '''
    if request.method == 'GET':
        return render(request, 'signup.html', {})
    elif request.method == 'POST':
        '''
        xff = request.META.get('HTTP_X_FORWARDED_FOR')
        if not xff:
            xff = request.META.get('REMOTE_ADDR')
        ip = xff.split(',')[-1].strip()
        r = valid(request.POST.get("vtoken", ''), request.POST.get("vserver", ''), ip)
        if not r:
            messages.error(request, '图形验证失败')
            request.session['hint'] = {"email": un}
            return redirect('/signin.html')
        '''
            
        un = request.POST.get("email", '')
        pwd = request.POST.get("password", '')
        rpwd = request.POST.get("passwordx", '')
        if not un or not pwd or not rpwd:
            messages.error(request, '输入的用户邮箱、密码无效。请重新输入。')
            request.session['hint'] = {"email": un}
            return redirect('/signup.html')

        if pwd != rpwd:
            messages.error(request, '两次输入的用户密码不一致。请重新输入。')
            request.session['hint'] = {"email": un}
            return redirect('/signup.html')

        user = User.objects.filter(username=un)
        if user:
            messages.error(request, '用户已存在。请重新输入。')
            request.session['hint'] = {"email": un}
            return redirect('/signup.html')
        else:
            emailed = AccountService.sendverify(un, pwd)
            '''
            ux = User.objects.create_user(username=un, password=pwd)
            ux.save()
            return redirect('/signin.html')
            '''
            if not emailed:
                messages.error(request, '激活邮件发送失败,请检查输入的邮箱是否有效。')
                request.session['hint'] = {"email": un}
                return redirect('/signup.html')
            else:
                request.session['email'] = un
                return redirect('/sent.html')

The complete Traceback

Traceback Switch to copy-and-paste view
C:\Python312\Lib\site-packages\django\core\handlers\exception.py, line 55, in inner
        return inner
    else:
        @wraps(get_response)
        def inner(request):
            try:
                response = get_response(request)
                               ^^^^^^^^^^^^^^^^^^^^^ …
            except Exception as exc:
                response = response_for_exception(request, exc)
            return response
        return inner
Local vars
C:\Python312\Lib\site-packages\django\core\handlers\base.py, line 197, in _get_response
        if response is None:
            wrapped_callback = self.make_view_atomic(callback)
            # If it is an asynchronous view, run it in a subthread.
            if iscoroutinefunction(wrapped_callback):
                wrapped_callback = async_to_sync(wrapped_callback)
            try:
                response = wrapped_callback(request, *callback_args, **callback_kwargs)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
            except Exception as e:
                response = self.process_exception_by_middleware(e, request)
                if response is None:
                    raise
        # Complain if the view returned None (a common error).
Local vars
D:\CRM\m.enginesoft.cn\1201\gw\auth\views\profile.py, line 87, in signup
            '''
            if not emailed:
                messages.error(request, '激活邮件发送失败,请检查输入的邮箱是否有效。')
                request.session['hint'] = {"email": un}
                return redirect('/signup.html')
            else:
                request.session['email'] = un
                return redirect('/sent.html')
                           ^^^^^^^^^^^^^^^^^^^^^^ …
@login_required
def member(request):
    return render(request, 'member.html', {})
def qqauth(request):
Local vars
C:\Python312\Lib\site-packages\django\shortcuts.py, line 49, in redirect
    Issues a temporary redirect by default; pass permanent=True to issue a
    permanent redirect.
    """
    redirect_class = (
        HttpResponsePermanentRedirect if permanent else HttpResponseRedirect
    )
    return redirect_class(resolve_url(to, *args, **kwargs))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
def _get_queryset(klass):
    """
    Return a QuerySet or a Manager.
    Duck typing in action: any class with a `get()` method (for
Local vars
C:\Python312\Lib\site-packages\django\shortcuts.py, line 180, in resolve_url
    # Handle relative URLs
    if isinstance(to, str) and to.startswith(("./", "../")):
        return to
    # Next try a reverse URL resolution.
    try:
        return reverse(to, args=args, kwargs=kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
    except NoReverseMatch:
        # If this is a callable, re-raise.
        if callable(to):
            raise
        # If this doesn't "feel" like a URL, re-raise.
        if "/" not in to and "." not in to:
Local vars
C:\Python312\Lib\site-packages\django\urls\base.py, line 88, in reverse
                else:
                    raise NoReverseMatch("%s is not a registered namespace" % key)
        if ns_pattern:
            resolver = get_ns_resolver(
                ns_pattern, resolver, tuple(ns_converters.items())
            )
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
reverse_lazy = lazy(reverse, str)
def clear_url_caches():
Local vars
C:\Python312\Lib\site-packages\django\urls\resolvers.py, line 769, in _reverse_with_prefix
        return self._reverse_with_prefix(lookup_view, "", *args, **kwargs)
    def _reverse_with_prefix(self, lookup_view, _prefix, *args, **kwargs):
        if args and kwargs:
            raise ValueError("Don't mix *args and **kwargs in call to reverse()!")
        if not self._populated:
            self._populate()
                 ^^^^^^^^^^^^^^^^ …
        possibilities = self.reverse_dict.getlist(lookup_view)
        for possibility, pattern, defaults, converters in possibilities:
            for result, params in possibility:
                if args:
Local vars
C:\Python312\Lib\site-packages\django\urls\resolvers.py, line 594, in _populate
                                bits,
                                p_pattern,
                                url_pattern.default_args,
                                url_pattern.pattern.converters,
                            ),
                        )
                else:  # url_pattern is a URLResolver.
                    url_pattern._populate()
                         ^^^^^^^^^^^^^^^^^^^^^^^ …
                    if url_pattern.app_name:
                        apps.setdefault(url_pattern.app_name, []).append(
                            url_pattern.namespace
                        )
                        namespaces[url_pattern.namespace] = (p_pattern, url_pattern)
                    else:
Local vars
C:\Python312\Lib\site-packages\django\urls\resolvers.py, line 573, in _populate
            apps = {}
            language_code = get_language()
            for url_pattern in reversed(self.url_patterns):
                p_pattern = url_pattern.pattern.regex.pattern
                p_pattern = p_pattern.removeprefix("^")
                if isinstance(url_pattern, URLPattern):
                    self._callback_strs.add(url_pattern.lookup_str)
                    bits = normalize(url_pattern.pattern.regex.pattern)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
                    lookups.appendlist(
                        url_pattern.callback,
                        (
                            bits,
                            p_pattern,
                            url_pattern.default_args,
Local vars
C:\Python312\Lib\site-packages\django\utils\regex_helper.py, line 160, in normalize
                        if terminal_char != ")":
                            result.append(Group((("%%(%s)s" % param), param)))
                            walk_to_end(ch, pattern_iter)
                        else:
                            result.append(Group((("%%(%s)s" % param), None)))
            elif ch in "*?+{":
                # Quantifiers affect the previous item in the result list.
                count, ch = get_quantifier(ch, pattern_iter)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
                if ch:
                    # We had to look ahead, but it wasn't need to compute the
                    # quantifier, so use this character next time around the
                    # main loop.
                    consume_next = False
Local vars
C:\Python312\Lib\site-packages\django\utils\regex_helper.py, line 272, in get_quantifier
    # Consume the trailing '?', if necessary.
    try:
        ch, escaped = next(input_iter)
    except StopIteration:
        ch = None
    if ch == "?":
        ch = None
    return int(values[0]), ch
                ^^^^^^^^^^^^^^ …
def contains(source, inst):
    """
    Return True if the "source" contains an instance of "inst". False,
    otherwise.
Local vars
Variable	Value
ch	
'}'
escaped	
False
input_iter	
<generator object next_char at 0x0000005FAD3B3060>
quant	
['{', 't', 'n', 'o']
values	
['{tno']

Otherwise, when i use redirect to absolute URL, it also occured error:

Dose I use redirect in wrong way? What is the correct way to use redirect?

It works as follows:

return redirect('./sent.html')

bou how to redirect successfully for absolute URL, such as redirect(‘https://www.baidu.com’)?