Django가 내 URL 패턴을 처리하는 방식이 이상하게 보입니다. 사용자가 로그인 한 다음 프로필 페이지로 리디렉션되어야합니다. 또한 사용자가 프로필을 편집 할 수있는 기능이 있습니다.Django - view, urld weirdness
urlpatterns=patterns('student.views',
(r'profile/$', login_required(profile,'student')),
(r'editprofile/$', login_required(editprofile,'student')),
)
이 학생이라는 앱입니다 : 여기
내 URL의 내 애플 리케이션 중 하나에 대한 패턴입니다. 사용자가/student/profile로 이동하면 프로필보기가 표시됩니다. 그들은/student/editprofile에 가면 editprofile 뷰를 얻어야합니다. login_required라는 함수를 설정하여 사용자에 대한 검사를 수행합니다. 단지 주석으로 처리 할 수있는 것보다 조금 더 복잡합니다. 여기은 login_required 것 :
Going to <function profile at 0x03015DF0>
Going to <function editprofile at 0x03015BB0>
:
def login_required(view,user_type='common'):
print 'Going to '+str(view)
def new_view(request,*args,**kwargs):
if(user_type == 'common'):
perm = ''
else:
perm = user_type+'.is_'+user_type
if not request.user.is_authenticated():
messages.error(request,'You must be logged in. Please log in.')
return HttpResponseRedirect('/')
elif request.user.is_authenticated() and user_type != 'common' and not request.user.has_perm(perm):
messages.error(request,'You must be an '+user_type+' to visit this page. Please log in.')
return HttpResponseRedirect('/')
return view(request,*args,**kwargs)
return new_view
어쨌든, 이상한 것은 내가 오른쪽 페이지에 도착하더라도/학생/프로파일을 방문 할 때, 다음과 같은 인쇄 login_required,이다
둘 다 왜 인쇄됩니까? 왜 둘 다 방문하려고합니까? 내가/학생/editprofile를 방문하려고 할 때
심지어 괴상는 프로필 페이지는 어떤 부하이며,이 인쇄 무슨이다 :
Going to <function profile at 0x02FCA370>
Going to <function editprofile at 0x02FCA3F0>
Going to <function view_profile at 0x02FCA4F0>
view_profile 완전히 다른 응용 프로그램의 기능입니다.
decorators.login_required() 및 decorators.permission_required()에 대한 참을 수없는 점은 무엇입니까? – hop