我正在學習 django,我真的無法解決這個錯誤,我嘗試修改每個檔案但我找不到問題所在。
錯誤:/topics/ 處的 OperationalError 沒有這樣的表:pizzas_topic
不得不提的是,這個練習來自 Python Crash Course 2nd Edition
謝謝
這是我的專案中的代碼:
base.html:
<p>
<a href="{% url 'pizzas:index' %}">Pizzeria</a> -
<a href="{% url 'pizzas:topics' %}">Pizzas</a>
</p>
{% block content %}{% endblock content %}
索引.html
{% extends "pizzas/base.html"%}
{% block content %}
<p>Pizzeria</p>
<p>Hi</p>
{% endblock content%}
主題.html
{% extends 'pizzas/base.html' %}
{% block content %}
<p>Topic: {{topic}}</p>
<p>Entries:</p>
<ul>
{% for entry in entries %}
<li>
<p>{{entry.date_added|date:'M d, Y H:i'}}</p>
<p>{{entry.text|linebreaks}}</p>
</li>
{% empty %}
<li>There are no entries for this topic yet.</li>
{% endfor %}
</ul>
{% endblock content %}
主題.html
{% extends "pizzas/base.html" %}
{% block content %}
<p> Topics</p>
<ul>
{% for topic in topics %}
<li>
<a href="{% url 'pizzas:topic' topic.id %}">{{ topic }}</a>
</li>
{% empty %}
<li>No topics have been addet yet.</li>
{% endfor %}
</ul>
{% endblock content %}
網址.py
"""Defines URL patterns for pizzeria."""
from django.urls import path
from . import views
app_name = 'pizzas'
urlpatterns = [
# Home page
path('',views.index, name='index'),
# Page that shows all pizzas.
path('topics/', views.topics, name='topics'),
# Detail page for a single topic.
path('topics/<int:topic_id>/', views.topic, name='topic'),
]
視圖.py
from django.shortcuts import render
from .models import Topic
def index(request):
"""The home page for Learning Log."""
return render(request, 'pizzas/index.html')
def topics(request):
"""Show all topics."""
topics = Topic.objects.order_by('date_added')
context = {'topics': topics}
return render(request,'pizzas/topics.html',context)
def topic(request, topic_id):
"""Show a single topic and all its entries."""
topic = Topic.objects.get(id=topic_id)
entries = topic.entry_set.order_by('-date_added')
context = {'topic': topic, 'entries': entries}
return render(request, 'pizzas/topic.html', context)
uj5u.com熱心網友回復:
跑:
python manage.py migrate
python manage.py makemigrations
python manage.py migrate
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/420501.html
標籤:
