UnYeong  Jeong

런서버에서 오류가납니다.

syntaxerror 인데요...

분명히 똑 같이 입력했는데 그렇습니다,

문제가 뭘까요?!

Unhandled exception in thread started by Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\django\utils
fn(*args, **kwargs)
File "C:\Anaconda3\lib\site-packages\django\core\
self.check(display_num_errors=True)
File "C:\Anaconda3\lib\site-packages\django\core\
include_deployment_checks=include_deployment_ch
File "C:\Anaconda3\lib\site-packages\django\core\
new_errors = check(app_configs=app_configs)
File "C:\Anaconda3\lib\site-packages\django\core\
return check_resolver(resolver)
File "C:\Anaconda3\lib\site-packages\django\core\
for pattern in resolver.url_patterns:
File "C:\Anaconda3\lib\site-packages\django\utils
res = instance.__dict__[self.name] = self.func(
File "C:\Anaconda3\lib\site-packages\django\core\
patterns = getattr(self.urlconf_module, "urlpat
File "C:\Anaconda3\lib\site-packages\django\utils
res = instance.__dict__[self.name] = self.func(
File "C:\Anaconda3\lib\site-packages\django\core\
return import_module(self.urlconf_name)
File "C:\Anaconda3\lib\importlib\__init__.py", li
return _bootstrap._gcd_import(name[level:], pac
File "", line 986, i
File "", line 969, i
File "", line 958, i
File "", line 673, i
File "", li
File "", line 222, i
File "C:\dev\mysite\mysite\urls.py", line 20, in
url(r'', include('elections.urls')), #주소, 누
File "C:\Anaconda3\lib\site-packages\django\conf\
urlconf_module = import_module(urlconf_module)
File "C:\Anaconda3\lib\importlib_init_.py", li
return _bootstrap._gcd_import(name[level:], pac
File "", line 986, i
File "", line 969, i
File "", line 958, i
File "", line 673, i
File "", li
File "", li
File "", li
File "", line 222, i
File "C:\dev\mysite\elections\urls.py", line 7
url(r'polls/(?P\d+)/$', views.polls),

7 개의 답변
정두식

urls.py의 내용을 올려주세요. 저것만 봐서는 이유를 모르겠네요.

UnYeong  Jeong

from django.conf.urls import url
from . import views #.은 현재 폴더라는 뜻

urlpatterns = [
url(r'$', views.index),
url(r'areas/(?P.+)/$',views.areas)
url(r'polls/(?P\d+)/$', views.polls),
]

이 상태입니다 ㅜㅜ 다음 강의로 넘어가고싶은데 가질 못하네요 ㅎㅎ

마크다운 문법이

<>

이 부등호 기호와 안의 내용물을 생략해서 에러 이름 부분이 안보입니다. 에러 출력 부분을

```

에러내용~

```

이런식으로 적어주시면 문제를 정확히 파악할 수 있을 것 같습니다

UnYeong  Jeong

'''
Unhandled exception in thread started by .wrapper at 0x0000015C3E855950>
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "C:\Anaconda3\lib\site-packages\django\core\management\base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "C:\Anaconda3\lib\site-packages\django\core\checks\registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "C:\Anaconda3\lib\site-packages\django\utils\functional.py", line 33, in get
res = instance.dict[self.name] = self.func(instance)
File "C:\Anaconda3\lib\site-packages\django\core\urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Anaconda3\lib\site-packages\django\utils\functional.py", line 33, in get
res = instance.dict[self.name] = self.func(instance)
File "C:\Anaconda3\lib\site-packages\django\core\urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Anaconda3\lib\importlib_init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 662, in exec_module
File "", line 222, in _call_with_frames_removed
File "C:\dev\mysite\mysite\urls.py", line 20, in
url(r'', include('elections.urls')), #주소, 누가 처리 / include는 앱 실행할 때 추가
File "C:\Anaconda3\lib\site-packages\django\conf\urls__init
.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "C:\Anaconda3\lib\importlib__init
_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 658, in exec_module
File "", line 764, in get_code
File "", line 724, in source_to_code
File "", line 222, in _call_with_frames_removed
File "C:\dev\mysite\elections\urls.py", line 7
url(r'polls/(?P\d+)/$', views.polls),
^
SyntaxError: invalid syntax
'''

이게 에러입니다!

이성용

정규 표현식에서 < url에서 함수로 전달해 주는 변수명 > 으로 < > 사이에 처리되는 함수로 전달해주는 변수 이름이 빠져있네요.

홍야

from django.conf.urls import url
from . import views
urlpatterns = [
url(r'$', views.index),
url(r'areas/(?P.+)/$', views.areas)
url(r'polls/(?p\d+)/$', views.polls)
]

  • 홍야
    url(r'^polls/(?p<poll_id>\d+)/$', views.polls) ― 홍야 2017.8.18 11:24
  • 홍야
    저두 에러가 납니다ㅜㅜ ― 홍야 2017.8.18 11:24
신동혁

def polls(request, poll_id):
poll = Poll.objects.get(pk = poll_id)
selection = request.POST['choice']

try: 
    choice = Choice.objects.get(poll_id = poll_id, candidate_id = selection)
    choice.votes += 1
    choice.save()
except:
    #최초로 투표하는 경우, DB에 저장된 Choice객체가 없기 때문에 Choice를 새로 생성합니다
    choice = Choice(poll_id = poll_id, candidate_id = selection, votes = 1)
    choice.save()

return HttpResponse("finish")

저도 같은 경우 때문에 틀렸었는데요

poll_id = poll.id가 아니고
poll_id = poll_id로 해야하는 것 같습니다.

답변 쓰기
이 입력폼은 마크다운 문법을 지원합니다. 마크다운 가이드 를 참고하세요.