2016-08-05 6 views
0

장고를 처음 사용하고 버전 1.9.8을 사용하고 있습니다. 나는 공식 튜토리얼을 따랐고, 지금은 this 더 진보 된 것을 시도하고있다. 나는 "등록 사용자"섹션의 마지막/체크 포인트에 있습니다. http://localhost:8000/register을 방문하면 Django는 static/templates/authentication/register.html에있는 자습서에서 생성 된 내용이 아닌 authentication/templates/authentication.html에있는 index.html 페이지에있는 콘텐츠를 표시합니다. 장고 URL에 문제가 있습니다

내가 처음에 내가 어디에 도착

, 나는

#urls.py 
from django.conf.urls import include,url 
from django.contrib import admin 
from django.conf.urls import patterns 

from rest_framework_nested import routers 
from authentication.views import AccountViewSet 

router = routers.SimpleRouter() 
router.register(r'accounts', AccountViewSet) 

urlpatterns = [ 
    url(r'^admin/', admin.site.urls), 
    url(r'^api/v1/', include(router.urls)), 
    url('^.*$', IndexView.as_view(), name='index'), #this line was causing the error 
] 

내가 같은 자습서를 다음 한 다른 사람에서 this post 가로 질러 온 urls.py를 참조, 다음과 같은 오류 ImportError: cannot import name 'IndexView'를 수신했다. 나는

from authentication.views import AccountViewSet, IndexView 

같은

로 내 urls.py에 IndexView 가져 오기를 추가 그리고 내 views.py

# authentication/views.py 
.... 
class IndexView(TemplateView): 
    template_name = 'mytestproject/index.html' #this page is showing when I visit http://localhost:8000/register rather than the one located at static/templates/authentication/register.html 

IndexView 오류가 멀리 가서 서버가 오류없이 실행에 IndexView 클래스를 추가 그러나 내가 방문했을 때 http://localhost:8000/register는 아무것도 보이지 않고 있었다. index.html 페이지를 열고 내용을 추가 한 다음 해당 내용을 표시했습니다. 장고 내가 명확하게 내가 만든 등록 페이지 대신에 authentication/templates/authentication.html에 위치한 색인 파일을 사용하고 있습니다. 장고에 등록 할 때 static/templates/authentication/register.html에 위치한 템플릿을 사용하려면 어떻게해야합니까? 주로 'register'라는 메소드가 튜토리얼 동안 뷰에 정의되지 않았거나 urls.py 파일에 지정되지 않았기 때문에 혼동 스럽다.

감사 '^.*$'에서

답변

1
url('^.*$', IndexView.as_view(), name='index'), 

.*

당신이 url.py에 등록 페이지 URL을 추가 did'nt 모든 URL이 IndexView로 이동합니다 말한다

url(r'^register/',views.yourview,name='givenameforthisurl') 
+0

그게 내가 혼란스러워하는 부분입니다. 튜토리얼이 진행되는 한 views.py에서 서버 측에 "등록"메소드가 생성되지 않았습니다. 해당 URL을 어떤보기 및 이름으로 제공합니까? 내가 만든 레지스터와 관련된 유일한 것은'static/templates/authentication/register.html'에 위치한 템플릿입니다. 튜토리얼에 컨텐츠가 누락되었거나 내가 이해하지 못하는 내용이 있습니까? 해당 템플릿에 액세스하기 위해 각도 라우팅에 의존하고 있습니까? 결국, 그것은 정적 폴더에 배치되었습니다. – user1852176

+0

예 페이지를 표시하는보기 기능을 작성해야하거나 django의 내장보기를 사용하는 경우 url.py에서 해당 패키지를 가져올 필요가 있습니다 (이 빌드 된 "인증보기"예제 참조) (https : // docs .djangoproject.com/ko/1.9/topics/auth/default/# module-django.contrib.auth.views) – masternone

관련 문제