微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SyntaxError: polls//urls.py 中的语法无效为什么我会收到这个错误?

如何解决SyntaxError: polls//urls.py 中的语法无效为什么我会收到这个错误?

我正在使用 django 3.1.7 并按照它创建应用程序文档。我被困在第 3 部分,因为它给出了语法错误

这里是 urls.py:

from django.urls import path
from polls import views

urlpatterns = [
    path('',views.index,name='index'),path('<int:question_id>/',views.detail,name='detail'),path('<int:question_id>/results/',views.results,name='results'),path('<int:question_id>/Vote/',views.Vote,name='Vote'),]

错误

(rookieCoderEnv) C:\Users\ORCUN\OneDrive\Masaüstü\WebDeveloperBootcamp\Djangoproject\rookieCoder>py 
manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\ORCUN\anaconda3\envs\rookieCoderEnv\lib\threading.py",line 954,in _bootstrap_inner
self.run()
File "C:\Users\ORCUN\anaconda3\envs\rookieCoderEnv\lib\threading.py",line 892,in run
self._target(*self._args,**self._kwargs)
File "C:\Users\ORCUN\anaconda3\envs\rookieCoderEnv\lib\site-packages\django\utils\autoreload.py",line 53,in wrapper
fn(*args,**kwargs)
File "C:\Users\ORCUN\anaconda3\envs\rookieCoderEnv\lib\site- 
packages\django\core\management\commands\runserver.py",line 118,in inner_run

  self.check(display_num_errors=True)
  File "C:\Users\ORCUN\anaconda3\envs\rookieCoderEnv\lib\site- 
 packages\django\core\management\base.py",line 392,in check
 all_issues = checks.run_checks(
File "C:\Users\ORCUN\anaconda3\envs\rookieCoderEnv\lib\site-packages\django\core\checks\registry.py",line 70,in run_checks
File "<frozen importlib._bootstrap>",line 1030,in _gcd_import
File "<frozen importlib._bootstrap>",line 1007,in _find_and_load
File "<frozen importlib._bootstrap>",line 986,in _find_and_load_unlocked
File "<frozen importlib._bootstrap>",line 680,in _load_unlocked
File "<frozen importlib._bootstrap_external>",line 786,in exec_module
File "<frozen importlib._bootstrap_external>",line 923,in get_code
File "<frozen importlib._bootstrap_external>",line 853,in source_to_code
File "<frozen importlib._bootstrap>",line 228,in _call_with_frames_removed
   File 
   "C:\Users\ORCUN\OneDrive\Masaüstü\WebDeveloperBootcamp\Djangoproject\rookieCoder\polls\urls.py",line 7
  path('<int:question_id>/results/'),^
SyntaxError: invalid Syntax

"C:\Users\ORCUN\OneDrive\Masaüstü\WebDeveloperBootcamp\Djangoproject\rookieCoder\polls\urls.py",7号线 path('int:question_id/results/'),

我对名字的遗漏是什么?我该如何解决

解决方法

错误在这里:

path('<int:question_id>/results/'),views.results,name='results'),

额外的右括号在传递其他参数之前结束路径方法调用。 改为:

path('<int:question_id>/results/',

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。