2017-12-23 7 views
-1

私は3つのページをメイン、1つと2つ持っています。私が必要とするのは、私がページのメインページにアクセスするときです。ページ1と2を表示する必要があります。Djangoテンプレートを作成するには、仕事が含まれています

HTML:

main.html

{% extends 'base.html' %} 
{% load staticfiles %} 
{% load my_tag %} 

{% block title %} 
    <title>Main TAB</title> 
{% endblock %} 


{% block body %} 
    <div> 
    {% include ‘test/one/’ %} 
    </div> 
    <div class="container"> 
    {{name}} 
    </div> 
    <script type="text/javascript" src="{% static "js/testquery.js"%}"> 
</script> 
{% endblock %} 

one.html

<div class="container"> 
    {{ name }} 
</div> 

two.html

TemplateSyntaxError at /taskmaster/Test/Main/ 
Could not parse the remainder: '‘test/one.html’' from '‘test/one.html’' 
Request Method: GET 
Request URL: http://localhost:8000/taskmaster/Test/Main/ 
Django Version: 2.0 
Exception Type: TemplateSyntaxError 
Exception Value:  
Could not parse the remainder: '‘test/one.html’' from '‘test/one.html’' 
Exception Location: C:\Program Files (x86)\Python36-32\lib\site-packages\django\template\base.py in __init__, line 668 
Python Executable: C:\Program Files (x86)\Python36-32\python.exe 
Python Version: 3.6.1 
Python Path:  
['C:\\Users\\i326707\\PycharmProjects\\opsboard', 
'C:\\Program Files (x86)\\Python36-32\\python36.zip', 
'C:\\Program Files (x86)\\Python36-32\\DLLs', 
'C:\\Program Files (x86)\\Python36-32\\lib', 
'C:\\Program Files (x86)\\Python36-32', 
'C:\\Program Files (x86)\\Python36-32\\lib\\site-packages', 
'C:\\Users\\i326707\\PycharmProjects\\opsboard\\commonpage', 
'C:\\Users\\i326707\\PycharmProjects\\opsboard\\taskmaster'] 
Server time: Sat, 23 Dec 2017 08:10:28 +0000 

答えて

1
<div class="container"> 
    {{ name }} 
</div> 

view.py

def main_page(request): 
    try: 
     main_data = {'name':"main"} 
     return render(request, 'task/main.html', {'name': main_data}) 

    except Exception as e: 
     raise 

def one_page(request): 
    try: 
     main_data = "one" 
     return render(request, 'task/one.html', {'name': main_data}) 

    except Exception as e: 
     raise 

def two_page(request): 
    try: 
     main_data = "Two" 
     return render(request, 'task/two.html', {'name': main_data}) 

    except Exception as e: 
     raise 

url.py

urlpatterns = [ 
    url(r'^$', taskpage,name="task_master"), 
    path('Task/<int:taskid>', show_task,name='show_task'), 
    path('Task/<int:taskid>/update', 
     updatetaskpage,name='updatetask_page'), 
    path('Test/Main/', main_page,name='main'), 
    path('Test/one/', one_page,name='one'), 
    path('Test/two/', two_page,name='two'), 
] 

私は、次のエラーを取得していますあなたのincludeタグに中括弧が入っていますが、これは無効です。それらを真っ直ぐな一重引用符で置き換えます。

0

Daniel Roseman's answerは、あなたが中かっこを使用していることを正しく示しています。これは修正する必要があります。

別の問題があります。あなたは間違ってURLをincludeに渡しています。代わりに、あなたが含むテンプレートにファイルパスを渡すべきです(templatesディレクトリを基準にして)。すなわち:

{% include 'task/one.html' %} 

docs for the include template tagを参照してください。

関連する問題