2016-05-23 9 views
1

wagtailでテンプレートタグを読み込む際に 'str'オブジェクトに属性 'relative_url'がありません。ここで'str'オブジェクトに属性 'relative_url'がありません

は私のタグコードは次のとおりです。

<form action="{% pageurl page %}" method="POST"> 

T:私は行を削除する場合

{% load wagtailcore_tags vdecristo_tags %} 
<form action="{% pageurl page %}" method="POST"> 
    {% csrf_token %} 
    <div class="shop-subscribe bg-color-green margin-bottom-40"> 
     <div class="container"> 
       <div class="row"> 
        <div class="col-md-8 md-margin-bottom-20"> 
          <h2>Subscribase para mantenerse<strong> informado</strong></h2> 
        </div> 




        <div class="col-md-4"> 
          <div class="input-group"> 


          <input type="text" class="form-control" placeholder="Correo Electronico..." {{ form.subscribase }}> 
            <span class="input-group-btn"> 
              <button class="btn" type="submit"><i class="fa fa-envelope-o"></i></button> 
            </span> 

          </div> 

           {{ form.subscribase.errors }} 
         </div> 
       </div> 
     </div><!--/end container--> 
    </div> 

</form> 

ここ
from django import template 
from home.models import * 

register = template.Library() 

@register.inclusion_tag('home/subscribe_form.html') 
def test_vdcristo(): 
    return {} 

は私のHTMLテンプレートのコードです彼はコンテンツの負荷を形成しますが、もちろん投稿しません。誰かが私にこれを解決する方法を理解するのを助けることができますか?

答えて

1

テンプレートコードで変数pageformが参照されていますが、タグコードから渡されていないため、これは失敗しています。 (私はここで見ることを期待したいエラーが'NoneType' object has no attribute 'relative_url'だろう - あなたのエラーは、page変数として文字列を渡していることを示唆している)、この作品を作るために

1つの可能な方法:

@register.inclusion_tag('home/subscribe_form.html') 
def test_vdcristo(): 
    # Look up the relevant form page by slug; replace FormPage and 'subscribe-now' 
    # as appropriate for your site 
    page = FormPage.objects.get(slug='subscribe-now') 
    return { 
     'page': page, 
     'form': page.get_form(), 
    } 
+0

test_vdcristoタグを読み込む際に、/ radio/'request'にエラーメッセージKeyErrorが表示されます。追加の提案はありますか? – Leo

+1

おそらく親テンプレートのコンテキストから 'request'変数を取得する必要があります。https://docs.djangoproject.com/en/1.9/howto/custom-template-tags/#の 'takes_context'に関するセクションを参照してください。 inclusion-tags - あなたが返す変数のリストの中で '' request ':context [' request '] 'を渡します。 – gasman

+0

'request'を渡しました:context ['request']が問題を修正しました。ありがとう! – Leo

0

あなたは

{% url url_name %} 

(予告:URL、ないPAGEURL)を使用する必要があり、URLで定義されたページという名前のURLを持っています。

+0

これでしょう一般的にはDjangoには間違いありませんが、Wagtailの{%pageurl ...%} 'は、Wagtailのページオブジェクトに対応するURLが必要な場合に使用する適切なタグです。 – gasman

関連する問題