pythondjangodjango-3.1

SyntaxError: invalid syntax in polls//urls.py . Why do i get this error?


I'm using django 3.1.7 and following it's create app documentation. I'm stuck at part 3 because it gives syntax error.

Here is the 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'),
]

Error:

(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", line 7 path('int:question_id/results/'), views.results, name='results'),

What is the thing that I'm missing about name? How can I fix it?


Solution

  • The mistake is here:

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

    Extra closing parenthesis ends the path method call before you pass other arguments. Change it to:

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