如何修复python3,django2中的“意外令牌']'“错误?

时间:2019-08-19 01:36:28

标签: python django

我正在尝试将该模块添加到urls.py。 这是代码:

"""
Definition of urls for learning_log.
"""

from datetime import datetime
from django.urls import path
from django.contrib import admin
from django.contrib.auth.views import LoginView, LogoutView
from app import forms, views
#added
from django.conf.urls import include, url
import learning_logs.views
from django.urls import path,re_path

app_name='learning_logs'
urlpatterns =[
    #added
    path('', include('learning_logs/urls',namespace='learning_logs'),

    path('contact/', views.contact, name='contact'),
    path('about/', views.about, name='about'),
    path('login/',
         LoginView.as_view
         (
             template_name='app/login.html',
             authentication_form=forms.BootstrapAuthenticationForm,
             extra_context=
             {
                 'title': 'Log in',
                 'year' : datetime.now().year,
             }
         ),
         name='login'),
    path('logout/', LogoutView.as_view(next_page='/'), name='logout'),
    path('admin/', admin.site.urls)]

代码似乎还不错,但是Visual Studio不断报告错误:

意外令牌']'

它说最后一个']'有问题,但这是语法的一部分。 如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

您在include learning_logs行上缺少右括号:

path('', include('learning_logs/urls',namespace='learning_logs'),

应为:

path('', include('learning_logs/urls',namespace='learning_logs')),