Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.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 __init_u3;()接受1个位置参数,但在登录页中指定了2个_Python_Html_Django - Fatal编程技术网

Python __init_u3;()接受1个位置参数,但在登录页中指定了2个

Python __init_u3;()接受1个位置参数,但在登录页中指定了2个,python,html,django,Python,Html,Django,所以我是python新手,我一直在尝试创建一个非常基本的登录页面,每当我查找这个错误时,所有的解决方案都非常特定于Person代码。我正在为我的comsci 3独立学习班学习python,我一直在制作一个非常简单的网站,所以我真的不知道如何解决这个问题。在登录/注销页面的前端和后端,我遇到了很多不同的错误。这是我的代码,谢谢你的帮助:) url.py from django.contrib import admin from django.urls import path from hello.

所以我是python新手,我一直在尝试创建一个非常基本的登录页面,每当我查找这个错误时,所有的解决方案都非常特定于Person代码。我正在为我的comsci 3独立学习班学习python,我一直在制作一个非常简单的网站,所以我真的不知道如何解决这个问题。在登录/注销页面的前端和后端,我遇到了很多不同的错误。这是我的代码,谢谢你的帮助:)

url.py

from django.contrib import admin
from django.urls import path
from hello.views import myView
from hello.views import myHome
from hello.views import home
from hello.views import index
from hello.views import game
from django.contrib.auth import views as auth_views
from django.views.generic.base import TemplateView
#from hello.views import index
from django.conf.urls import url, include
urlpatterns = [
    #path('admin/', admin.site.urls),
    url(r'^admin/',admin.site.urls),
    url(r'^hello/',include('hello.urls')),
    path('sayHello/', myView),
    path('home/',home,name='Home'),
    path('game/',game),
    path('home/game.html',game),
    path('home/home.html',home),
    path('game/game.html',game),
    path('game/home.html',home),
    url(r'^login/$', auth_views.LoginView, {'template_name': 'login.html'}, name='login'),
    url(r'^logout/$', auth_views.LogoutView, {'template_name': 'logged_out.html'}, name='logout'),

]
login.html

{% extends 'base.html' %}
{% block title %}Login{% endblock %}

{% block content %}
  <h2>Login</h2>
  <form method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Login</button>
  </form>
{% endblock %}
{% extends 'base.html' %}

{% block title %}See you! {% endblock %}

{% block content %}
  <h2>Logged out</h2>
  <p>You have been successfully logged out.</p>
  <p><a href="{% url 'login' %}">Log in</a> again.</p>
{% endblock %}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{% block title %}Django Simple Login{% endblock %}</title>
</head>
<body>
  <header>
    <h1>Django Simple Login</h1>
    {% if user.is_authenticated %}
      Hi {{ user.username }}!
      <a href="{% url 'logout' %}">logout</a>
    {% else %}
      <a href="{% url 'login' %}">login</a>
    {% endif %}
  </header>
  <hr>
  <main>
    {% block content %}
    {% endblock %}
  </main>
  <hr>
  <footer>
    <a href="http://simpleisbetterthancomplex.com">simpleisbetterthancomplex.com</a>
  </footer>
</body>
</html>
{%extends'base.html%}
{%block title%}登录名{%endblock%}
{%block content%}
登录
{%csrf_令牌%}
{{form.as_p}}
登录
{%endblock%}
注销。html

{% extends 'base.html' %}
{% block title %}Login{% endblock %}

{% block content %}
  <h2>Login</h2>
  <form method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Login</button>
  </form>
{% endblock %}
{% extends 'base.html' %}

{% block title %}See you! {% endblock %}

{% block content %}
  <h2>Logged out</h2>
  <p>You have been successfully logged out.</p>
  <p><a href="{% url 'login' %}">Log in</a> again.</p>
{% endblock %}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{% block title %}Django Simple Login{% endblock %}</title>
</head>
<body>
  <header>
    <h1>Django Simple Login</h1>
    {% if user.is_authenticated %}
      Hi {{ user.username }}!
      <a href="{% url 'logout' %}">logout</a>
    {% else %}
      <a href="{% url 'login' %}">login</a>
    {% endif %}
  </header>
  <hr>
  <main>
    {% block content %}
    {% endblock %}
  </main>
  <hr>
  <footer>
    <a href="http://simpleisbetterthancomplex.com">simpleisbetterthancomplex.com</a>
  </footer>
</body>
</html>
{%extends'base.html%}
{%block title%}再见!{%endblock%}
{%block content%}
注销
您已成功注销

再说一遍

{%endblock%}
base.html

{% extends 'base.html' %}
{% block title %}Login{% endblock %}

{% block content %}
  <h2>Login</h2>
  <form method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Login</button>
  </form>
{% endblock %}
{% extends 'base.html' %}

{% block title %}See you! {% endblock %}

{% block content %}
  <h2>Logged out</h2>
  <p>You have been successfully logged out.</p>
  <p><a href="{% url 'login' %}">Log in</a> again.</p>
{% endblock %}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{% block title %}Django Simple Login{% endblock %}</title>
</head>
<body>
  <header>
    <h1>Django Simple Login</h1>
    {% if user.is_authenticated %}
      Hi {{ user.username }}!
      <a href="{% url 'logout' %}">logout</a>
    {% else %}
      <a href="{% url 'login' %}">login</a>
    {% endif %}
  </header>
  <hr>
  <main>
    {% block content %}
    {% endblock %}
  </main>
  <hr>
  <footer>
    <a href="http://simpleisbetterthancomplex.com">simpleisbetterthancomplex.com</a>
  </footer>
</body>
</html>

{%block title%}Django简单登录名{%endblock%}
Django简单登录
{%if user.u经过身份验证%}
你好{{user.username}!
{%else%}
{%endif%}

{%block content%} {%endblock%}

由于
LoginView
LogoutView
是基于类的视图,因此需要使用传递这些视图的函数来处理请求:

urlpatterns = [
    # …
    url(r'^login/$', auth_views.LoginView.as_view(template_name='login.html'), name='login'),
    url(r'^logout/$', auth_views.LogoutView.as_view(template_name='logged_out.html'), name='logout'),
]
urlpatterns=[
# …
url(r“^login/$”,auth_views.LoginView.as_view(template_name='login.html'),name='login'),
url(r“^logout/$”,auth_views.LogoutView.as_view(template_name='logged_out.html'),name='logout'),

]
应该是
url.py
中的
auth\u views.LoginView.as\u view()
auth\u views.LogoutView.as\u view()
。谢谢你,因为我是python新手,我不太了解基于类的视图需要调用.as\u view()方法。但是我想知道这个错误到底是什么性质的,比如为什么会发生这个错误,这样将来我就知道调试时我在寻找什么了。@idianskilz:如果你不使用
。\u view(…)
你将调用
LoginView
构造函数,而该构造函数并不打算处理请求(和其他参数)。