我是初学者,我正在线上学习。我试图复制什么教练我的如何,但它不工作,我不知道为什么。如果你们能帮助我们真的很感激。
我运行服务器并转到主页,在这种情况下只是http://127.0.0.1:8000/
但是当我去http://127.0.0.1:8000/signups时,似乎没有任何事情发生,它只是继续显示主页。没有错误显示
这是我的相关文件:
App Level --------
AppThree / forms.py文件
from django import forms
from AppThree.models import User
# Create your models here.
class NewUserSignUp(forms.ModelForm):
class Meta:
model = User
fields = '__all__'
AppThree / models.py
from django.db import models
# Create your models here.
class User(models.Model):
firstName = models.CharField(max_length=125)
lastName = models.CharField(max_length = 125)
email = models.EmailField(unique=True, max_length=265)
AppThree / urls.py
from django.conf.urls import url
from AppThree import views
urlpatterns = [
url(r'^$', views.NewUserSignUp, name='NewUserSignUp'),
]
AppThree / views.py
from django.shortcuts import render
from AppThree.forms import NewUserSignUp
# Create your views here.
def home(request):
return render(request, 'AppThree/home.html')
def NewUserSignUp(request):
form = NewUserSignUp()
if request.method == "POST":
form = NewUserSignUp(request.POST)
if form.is_valid():
form.save(commit=True)
return home(request)
print("Validation Success")
else:
print("Error")
return render(request, 'AppThree/SignUp.html',{'form':form})
结束应用级别--------------
项目级别----------
ProThree / urls.py
from django.conf.urls import url, include
from django.contrib import admin
from AppThree import views
urlpatterns = [
url(r'^', views.home,name='home'),
url(r'^signup/', include('AppThree.urls')),
url(r'^admin/', admin.site.urls),
]
endproject level -------
模板级别----
模板/ AppThree / home.html的
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home Page</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1>Well you gott his far.</h1>
<h2>step 2: create a signup page</h2>
</div>
</body>
</html>
模板/ AppThree / SignUp.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SignUp</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1>This is your signup page</h1>
<form method="POST">
{{ form.as_p }}
{% csrf_token %}
<input type="Submit" class="btn btn-primary" value="Submit">
</form>
</div>
</body>
</html