我在models.py
文件中添加了新列,保存了我的代码,然后在Terminal
我运行sudo python manage.py makemigrations music
后跟sudo python manage.py migrate
。运行sudo python manage.py migrate
后,我在Terminal
中收到错误消息:
这是我的index.html
文件:
<!DOCTYPE html>
<html lang="en">
<head>
<title>The Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
{% load static %}
<link rel="stylesheet" href="{% static 'index.css' %}">
</head>
<body>
<form class="col-md-4 col-md-offset-4" method="POST" name="formHandler">
{% csrf_token %}
<div class="userNameMovement">
<label for="usr">Email:</label>
<input class="form-control" id="email" name="email" placeholder="email" required="required">
</div>
<div class="passwordMovement">
<label for="usr">Username:</label>
<input class="form-control" id="userName" name="userName" placeholder="Username" required="required">
<button type="submit" class="btn btn-default">Submit</button>
</form>
</body>
</html>
这是我的models.py
文件:
from django.db import models
class Person(models.Model):
email = models.CharField(max_length=20, default=4)
userName = models.CharField(max_length=20, default=4)
def __str__(self):
return self.email + " - " + self.userName
class UI(models.Model):
person = models.ForeignKey(Person, on_delete=models.CASCADE)
这是我的views.py
文件:
from django.http import HttpResponse
from django.shortcuts import render
from .models import Person
def index(request):
if request.method == 'POST':
email = request.POST.get('email')
userName = request.POST.get('userName')
if email and userName:
user = Person.objects.create(email=email, username=userName)
user.save()
return render(request, 'music/index.html')
def detail(request, user_id): # Testing out page 2
return HttpResponse("<h2>Page # (testing this out) " + str(user_id) + "</h2>")
答案 0 :(得分:0)
您发布的终端输出没有错误。它只是告诉你数据库中发生了什么。
除非有其他错误消息,否则一切都应该没问题。