2013-08-06 22 views
0

問題的簡單性在於,「用戶」對象可以在開發服務器上的Django模板中訪問,但不能在Apache服務器上訪問。我在TEMPLATE_CONTEXT_PROCESSORS中啓用了'django.core.context_processors.request'。Django - 無法訪問Apache服務器中的「用戶」,在開發服務器上工作

下面是從行爲像它應該開發服務器上的模板的示例一段代碼,而不是Apache服務器上(我把用戶和request.user只是爲了測試它):

{{ user.get_profile.user_type }} 
{{ request.user.get_profile.user_type }} 

而這裏的一個觀點:

class NotificationsListView(LoginRequiredMixin, CorrectUserMixin, TemplateView): 

    error_message = 'Oops, something went wrong. \ 
        The browser was trying to access someone else\'s notification list.' 

def get_context_data(self, **kwargs): 
     my_id   = self.request.user.id 
     user_type  = self.request.user.get_profile().user_type 

     if user_type == 'Developer': 
      self.template_name = 'my_notifications_developer.html' 
      notifications  = RequestNotification.objects.filter(receiver__id = my_id, seen=False).order_by('-time_created') 
     else: 
      self.template_name = 'my_notifications_charity.html' 
      notifications  = RequestNotification.objects.filter(receiver__id = my_id, seen=False).order_by('-time_created') 

     # needed for correct user mixin 
     self.url_id   = self.kwargs['pk'] 
     return { 
      'params': kwargs, 
      'notifications': notifications, 
     } 
+0

嘗試使用django-debug-toolbar在調試模式下暫時**運行您的站點,以檢查哪些變量可用於模板。 – bouke

+0

謝謝你今晚會和我一起玩,我甚至沒有意識到有這樣的工具。另外,我可以首先在我的本地Apache服務器上測試它。 – MikkoP

回答

0

哦,我的上帝,這只是我的一個愚蠢的錯誤,我會創造在管理界面的輪廓,並沒有手動附加用戶配置文件到用戶對象...

相關問題