SyntaxError: invalid syntax in polls//urls.py . Why do i get this error?
SyntaxError: invalid syntax in polls//urls.py . Why do i get this error?
我正在使用 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/'), views.results, name='results'),
^
SyntaxError: invalid syntax
"C:\Users\ORCUN\OneDrive\Masaüstü\WebDeveloperBootcamp\DjangoProject\rookieCoder\polls\urls.py",
第 7 行
路径('int:question_id/results/'),views.results,名称='results'),
关于名字,我缺少什么?我该如何解决?
错误在这里:
path('<int:question_id>/results/'), views.results, name='results'),
额外的右括号在您传递其他参数之前结束路径方法调用。
将其更改为:
path('<int:question_id>/results/', views.results, name='results'),
我正在使用 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/'), views.results, name='results'),
^
SyntaxError: invalid syntax
"C:\Users\ORCUN\OneDrive\Masaüstü\WebDeveloperBootcamp\DjangoProject\rookieCoder\polls\urls.py", 第 7 行 路径('int:question_id/results/'),views.results,名称='results'),
关于名字,我缺少什么?我该如何解决?
错误在这里:
path('<int:question_id>/results/'), views.results, name='results'),
额外的右括号在您传递其他参数之前结束路径方法调用。 将其更改为:
path('<int:question_id>/results/', views.results, name='results'),