我在模型中拼写错误,现在我的一个列拼写错误了.我想删除数据库中的所有表,修复model.py中的错误,并在模型中使用正确的拼写重新创建数据库.
我试着用在建议这篇文章,但我按照列出存在的命令后,表仍然存在.
有人有快速的方法吗?
我正在研究Django的民意调查教程。到第六部分开始为止,我已经做到了。
由于某种原因,除了基于类的索引视图之外,我所有基于类的通用视图都在工作。尝试加载localhost:8000 /时,出现以下错误:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/
^admin/
The current URL, , didn't match any of these.
Run Code Online (Sandbox Code Playgroud)
这是我的mysite / urls.py:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
Run Code Online (Sandbox Code Playgroud)
这是我的民意调查/ urls.py
from django.conf.urls import url
from . import views
app_name = 'polls'
urlpatterns = [ …Run Code Online (Sandbox Code Playgroud) 我刚刚学习 CBV,并且在将对象传递给 TemplateView 时遇到了困难。这非常令人沮丧,因为我知道这应该是非常基本的。
这是我的观点.py:
from __future__ import absolute_import
from django.views import generic
from company_account.models import CompanyProfile
class CompanyProfileView(generic.TemplateView):
template_name = 'accounts/company.html'
def get_context_data(self, **kwargs):
context = super(CompanyProfileView, self).get_context_data(**kwargs)
return CompanyProfile.objects.all()
Run Code Online (Sandbox Code Playgroud)
这是我的 Models.py:
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
class CompanyProfile(models.Model):
company_name = models.CharField(max_length=255)
def __str__(self):
return self.company_name
Run Code Online (Sandbox Code Playgroud)
这是 urls.py
urlpatterns = [
url(r'^accounts/companyprofile/$', CompanyProfileView.as_view()),
]
Run Code Online (Sandbox Code Playgroud)
最后,这是模板:
{% extends '_layouts/base.html' %}
{% block title %}Company Profile{% endblock %}
{% block …Run Code Online (Sandbox Code Playgroud)