【问题标题】:Django 1.8 Domain Tutorial #3Django 1.8 域教程#3
【发布时间】:2015-09-23 17:10:10
【问题描述】:
投票/模板/投票/index.html
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
上面的 index.html 来自 Django 1.8 的教程 #3。我的问题是 index.html 在哪里/如何知道要使用哪个域?
【问题讨论】:
标签:
django
django-templates
django-views
【解决方案1】:
index.html 文件将与视图相关联,并且该视图将与将在 urls.py 文件中配置的 url 相关联。
当您将项目上传到服务器时,您将配置服务器配置,将您的项目链接到域。
例如:myawesomedomain.com
views.py
def HomeView(request):
return render(request, 'index.html', {context})
def ContactView(request):
return render(request, 'contact.html', {context})
urls.py
from django.conf.urls import patterns, include, url
from . import views
urlpatterns = patterns('',
url(r'^$', views.HomeView), # http://myawesomedomain.com
url(r'^contact$', views.ContactView), # http://myawesomedomain.com/contact
)