Ich verstehe nicht, wo mein Problem liegt. Ich bekomme ein Problem mit den URLs, aber ich sehe nicht, wo ich einen Fehler gemacht habe.Seite nicht gefunden 404 mit Django
Ich habe ein Projekt: Etat_civil
Ich habe eine App: BirthCertificate
Mein views.py app
ist:
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from BirthCertificate.forms import BirthCertificateForm
# Create your views here.
def BirthCertificateAccueil(request) :
# Fonction permettant de créer la page d'accueil de la rubrique Acte de Naissance
#Cherche le fichier html accueil et le renvois
template = loader.get_template('accueil.html')
return HttpResponse(template.render(request))
def BirthCertificateCreationAccueil(request) :
# Fonction permettant de créer la page de création du formulaire de la partie : Acte de Naissance
template = loader.get_template('creation_accueil.html')
return HttpResponse(template.render(request))
def BirthCertificateForm(request) :
if request.method == 'POST' :
form = BirthCertificateForm(request.POST)
if form.is_valid():
numero_acte = form.cleaned_data["Numero de l'acte"]
nom = form.cleaned_data['Nom']
prenom = form.cleaned_data['Prenom']
else :
form = BirthCertificateForm()
template = loader.get_template('birthform.html')
return render(request, template.render(request),locals())
Ich habe auch eine urls.py app
:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^accueil$', views.BirthCertificateAccueil),
url(r'^creation$', views.BirthCertificateCreationAccueil),
url(r'^formulaire$', views.BirthCertificateForm),
]
Und mein.210 wie folgt aussieht:
from django.conf.urls import url, include
from django.contrib import admin
from BirthCertificate import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^BirthCertificate/', include('BirthCertificate.urls')),
]
Die birthform.html Datei wie folgt aussieht:
{% if envoi %} Votre formulaire est bien complété ! {% endif %}
<form action="{% url "BirthCertificate.views.BirthCertificateForm" %}" method="post">{%
csrf_token %}
{{ form.as_table }}
<input type ="submit" value="Valider" />
</form>
Wenn ich starten: http://localhost:8000/BirthCertificate/formulaire
ich diesen Fehler:
Seite nicht gefunden (404) Anfrage Methode: GET Anfrage
URL: http://localhost:8000/BirthCertificate/formulaire Mit dem URLconf in Etat_civil.urls definiert, versucht Django diese URL-Muster, in dieser Reihenfolge:
^admin/
^Birthcertificate/^ accueil $
^Birthcertificate/^ creation $
Die aktuelle URL, BirthCertificate/formulaire, stimmte nicht mit überein. Sie sehen diesen Fehler, weil Sie in Ihrer Django-Einstellungsdatei DEBUG = True haben. Ändern Sie das in False und Django zeigt eine Standard-404-Seite an.
Ich bin fest mit Django und ich würde gerne wissen, ob Sie den Fehler sehen?
Vielen Dank!
#EDIT:
hatte ich einen Fehler in meiner forms.py
: Ich max_lenght
statt max_length
schrieb. Aber ich bekomme immer einen Fehler:
TypeError at /BirthCertificate/formulaire
BirthCertificateForm() missing 1 required positional argument: 'request'
Request Method: GET
Request URL: http://localhost:8000/BirthCertificate/formulaire
Django Version: 1.10.3
Exception Type: TypeError
Exception Value:
BirthCertificateForm() missing 1 required positional argument: 'request'
Exception Location: /Users/valentinjungbluth/Desktop/Django/Etat_civil/BirthCertificate/views.py in BirthCertificateForm, line 34
Python Executable: /Library/Frameworks/Python.framework/Versions/3.5/bin/python3
Python Version: 3.5.2
Python Path:
['/Users/valentinjungbluth/Desktop/Django/Etat_civil',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages']
Server time: Sun, 20 Nov 2016 16:16:16 +0000
Haben Sie den Server neu gestartet? –
@DanielRoseman Ja, ich habe den Port beendet, mache wieder einen Runserver und immer diesen Fehler. Jedoch,/accueil und/creation woks gut, also verstehe ich nicht. – Deadpool
versuchen Sie, Ihre Ansicht 'BirthCertificateForm' in' BirthCertificateView' umzubenennen, nicht sicher, aber möglicherweise gibt es einige Namen Konflikt – devxplorer