0

我遇到了問題,我找不到解決此問題的方法。 所有似乎都很好,但它不起作用。使用Django CBV模型重定向後的白色HTML頁面

這是這個過程:

我有關於它只是Django的形式創建的對象的所有信息的模板。 我有一個按鈕,必須重定向到其他模板考慮object id,但是當我重定向到這個模板,我得到一個html白頁。

這是我的模型:

class Societe(models.Model): 

    NumeroIdentification   = models.CharField(max_length=30, null=True, verbose_name='Numero Identification physique', unique=True) 
    Nom        = models.CharField(null= False, max_length=30, verbose_name='Nom de Société') 
    Etat       = models.CharField(max_length = 30, choices = CHOIX_ETAT_SOCIETE, null=False, verbose_name="Etat") 
    ... 

    def get_absolute_url(self): 
     return reverse_lazy('SocieteResume', kwargs={'id': self.id}) 

    def __unicode__(self): 
     return unicode (self.id, self.NumeroIdentification, self.Nom, ...) 

我有讓細節顯示創建對象的第一類:

class IdentitySocieteResumeView(LoginRequiredMixin, ListView) : 

    template_name = 'Identity_Societe_Resume.html' 
    model = Societe 

    def get_context_data(self, **kwargs) : 

     context_data = super(IdentitySocieteResumeView, self).get_context_data(**kwargs) 

     id = self.kwargs['id'] 
     societe = get_object_or_404(Societe, pk=id) 

     obj = Societe.objects.filter (Nom=societe.Nom, SIRET=societe.SIRET, SIREN=societe.SIREN, Ville=societe.Ville) 

     if obj: 
      sc_obj = obj[0] 

      ... 

     return context_data 

與已以重定向到該按鈕關聯的模板下一個模板:

<form method='POST' action="{% url 'SocietePDF' societe.id %}">{% csrf_token %} 
{% csrf_token %} 
<button>Générer le PDF de la Fiche d'Identification </button> 
</form> 

此按鈕重定向到(我必須得到id纔能有個性化視圖/模板):

class IdentitySocietePDFCreatingView(LoginRequiredMixin, TemplateView) : 

    template_name = 'Identity_Societe_PDF.html' 
    model = Societe 

    def get_context_data(self, **kwargs) : 

     context_data = super(IdentitySocietePDFCreatingView, self).get_context_data(**kwargs) 

     id = self.kwargs['id'] 
     societe = get_object_or_404(Societe, pk=id) 

     obj = Societe.objects.filter (Nom=societe.Nom, SIRET=societe.SIRET, SIREN=societe.SIREN, Ville=societe.Ville) 

     ... 

     return context_data 

我的urls.py文件看起來像這樣:

from django.conf.urls import url 
from Identity.views import IdentityIndividuFormView, IdentityHomepageView, IdentityChoiceUpdateView, IdentitySocieteFormView, IdentitySocieteResumeView, IdentitySocietePDFCreatingView 
from . import views 

urlpatterns = [ 
    url(r'^Homepage$', IdentityHomepageView.as_view(), name="Home"), 
    url(r'^Person/ChoiceUpdate/$', IdentityChoiceUpdateView.as_view(), name="IdentityChoice"), 
    url(r'^Person/Form/$', IdentityIndividuFormView.as_view(), name="IndividuFormulaire"), 
    url(r'^Company/Form/$', IdentitySocieteFormView.as_view(), name = "SocieteFormulaire"), 
    url(r'^Person/Form/Resume/(?P<id>\d+)/$', views.IdentityIndividuResume, name="IndividuResume"), 
    url(r'^Company/Form/Resume/(?P<id>\d+)/$', IdentitySocieteResumeView.as_view(), name="SocieteResume"), 
    url(r'^Person/Update/$', views.IdentityIndividuUpdateAll, name="Edition"), 
    url(r'^Company/Update/$', views.IdentitySocieteUpdateAll, name="EditionSociete"), 
    url(r'^Person/Research/$', views.IdentityIndividuResearching, name="IndividuRecherche"), 
    url(r'^Company/Research/$', views.IdentitySocieteResearching, name="SocieteRecherche"), 
    url(r'^Company/Research/Fraud/$', views.IdentitySocieteFraudResearching, name="SocieteRechercheFraude"), 
    url(r'^Company/Research/Employe/$', views.IdentitySocieteEmploye, name="SocieteRechercheEmploye"), 
    url(r'^Person/Read/PDF/$', views.IdentityIndividuPDFReading, name="Consultation"), 
    url(r'^Company/Read/PDF/$', views.IdentitySocietePDFReading, name="SocieteConsultation"), 
    url(r'^Person/Delete/$', views.IdentityIndividuDelete, name="Suppression"), 
    url(r'^Person/Form/PDF/(?P<id>\d+)/$', views.IdentityIndividuPDFCreating, name="IndividuPDF"), 
    url(r'^Company/Form/PDF/(?P<id>\d+)/$', IdentitySocietePDFCreatingView.as_view(), name="SocietePDF"), 
    url(r'^Statistics/$', views.IdentityStatistics, name="Statistiques"), 
    url(r'^Person/Update/Civility/$', views.IdentityIndividuUpdateCivility, name="EditionCivilite"), 
    url(r'^Person/Update/Coordonates/$', views.IdentityIndividuUpdateCoordonates, name="EditionCoordonnees"), 
    url(r'^Person/Update/Contact/$', views.IdentityIndividuUpdateContact, name="EditionContact"), 
] 

奇怪的是:當我才能被重定向到按鈕點擊SocietePDF我得到一個白色的HTML頁面,但如果我剪切/粘貼的網址,我可以訪問模板。

我的過程中缺少某些東西?

謝謝!

+0

在「空白」和非空白「白色」的情況下,使用「白色」燈光。 –

+0

@DanielRoseman對不起,我的意思是我的html頁面全是白色的,但空白更適應^^我不知道你說法語語言;) – Deadpool

+1

我有很多天賦...... :)無論如何,有一件事我會嘗試將更改表單操作從POST到GET,因爲您的IdentitySocietePDFCreatingView不期望POST請求。 –

回答

2

您的IdentitySocietePDFCreatingView不期待POST請求;您應該將表單操作更改爲GET。