Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';无法登录Heroku部署的应用程序,但可以在本地登录_Python_Django - Fatal编程技术网

Python Can';无法登录Heroku部署的应用程序,但可以在本地登录

Python Can';无法登录Heroku部署的应用程序,但可以在本地登录,python,django,Python,Django,在我的web应用程序中,注册和登录在我使用正在开发的服务器时效果很好,但当我在Heroku上部署该网站时,效果不佳。。只有使用createsuperuser创建的用户才能工作 另外,注册后用户会在注册后自动登录 但是当他们注销时。。他们无法再次登录 这是我的代码: 注册视图 def signup(request): current_user_ip = get_client_ip(request) current_temp = Temp.objects.filter(created

在我的web应用程序中,注册和登录在我使用正在开发的服务器时效果很好,但当我在Heroku上部署该网站时,效果不佳。。只有使用
createsuperuser
创建的用户才能工作

另外,注册后用户会在注册后自动登录

但是当他们注销时。。他们无法再次登录

这是我的代码:

注册视图

def signup(request):
    current_user_ip = get_client_ip(request)
    current_temp = Temp.objects.filter(created_by_ip=current_user_ip)
    current_temp.delete()
    if request.method == 'POST':
        signup_form = SignUpForm(request.POST, request.FILES)
        if signup_form.is_valid():
            signup_form.save()
            messages.info(request, "Thanks for registering. You are now logged in.")
            new_user = authenticate(username=signup_form.cleaned_data['email'],
                                    password=signup_form.cleaned_data['password1'],
                                    )
            login(request, new_user)
            return redirect('dashboard')
    else:
        signup_form = SignUpForm()

    context = {
        'signup_form': signup_form,
    }
    return render(request, 'signup.html', context)
forms.py

class EmailAuthForm(AuthenticationForm):
    def clean_username(self):
        return self.cleaned_data["username"].lower()


class SignUpForm(UserCreationForm):
    email = forms.EmailField(required=True, help_text='Must be a valid E-mail')
    user_name = forms.CharField(required=True, help_text='')
    password1 = forms.CharField(widget=forms.PasswordInput,
                                help_text='')
    password2 = forms.CharField(widget=forms.PasswordInput,
                                help_text='Password confirmation')
    avatar = forms.ImageField()

    class Meta:
        model = User
        fields = ('email', 'user_name', 'password1', 'password2', 'avatar')
        labels = {
            'user_name': 'user_name',
            'email': ' email',
            'password1': 'password1',
            'password2': 'password2',
            'avatar': 'avatar',
        }

    def clean_email(self):
        data = self.cleaned_data['email']
        return data.lower()
path('login/', auth_views.LoginView.as_view(authentication_form=EmailAuthForm), name="login"),
path('signup/', web_site_views.signup, name='signup'),
url.py

class EmailAuthForm(AuthenticationForm):
    def clean_username(self):
        return self.cleaned_data["username"].lower()


class SignUpForm(UserCreationForm):
    email = forms.EmailField(required=True, help_text='Must be a valid E-mail')
    user_name = forms.CharField(required=True, help_text='')
    password1 = forms.CharField(widget=forms.PasswordInput,
                                help_text='')
    password2 = forms.CharField(widget=forms.PasswordInput,
                                help_text='Password confirmation')
    avatar = forms.ImageField()

    class Meta:
        model = User
        fields = ('email', 'user_name', 'password1', 'password2', 'avatar')
        labels = {
            'user_name': 'user_name',
            'email': ' email',
            'password1': 'password1',
            'password2': 'password2',
            'avatar': 'avatar',
        }

    def clean_email(self):
        data = self.cleaned_data['email']
        return data.lower()
path('login/', auth_views.LoginView.as_view(authentication_form=EmailAuthForm), name="login"),
path('signup/', web_site_views.signup, name='signup'),

保存
返回用户,您应该检查以确保它正确返回。我是否应该在Auth函数中返回用户??我不明白。请解释更多(我还是Django初学者)如果您使用的是任何半高级IDE,您应该能够中断代码以检查值:)