Page not found (404) at /user_signup in Django

2024/10/9 21:19:04

Getting 404 error on signup and some more URLs. /login, /logout, /admin is working perfectly. I'm making a web app that lets a user login, logout, search a flight, book a flight and view the bookings made.

urls.py

from django.urls import path
from . import viewsurlpatterns = [path('', views.home, name='home'),path('search_flights/', views.search_flights, name='search_flights'),path('book_flight/<int:flight_id>/', views.book_flight, name='book_flight'),path('my_bookings/', views.my_bookings, name='my_bookings'),path('login/', views.user_signup, name='login'),path('signup/', views.user_signup, name='signup'),]

views.py

from django.shortcuts import render, redirect
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from .models import Flight, Booking
from django.contrib.auth.forms import UserCreationForm
from .forms import SignUpForm, SignInForm, EditProfileFormdef home(request):flights = Flight.objects.all()return render(request, 'home.html', {'flights': flights})@login_required
def search_flights(request):if request.method == 'POST':date = request.POST.get('date')time = request.POST.get('time')flights = Flight.objects.filter(date=date, time=time)return render(request, 'search_flights.html', {'flights': flights})return render(request, 'search_flights.html')@login_required
def book_flight(request, flight_id):flight = Flight.objects.get(id=flight_id)if request.method == 'POST':# Check if seats are availableif flight.seats_available() > 0:# Book the ticketbooking = Booking.objects.create(flight=flight, user=request.user)return redirect('my_bookings')else:# Show error messagereturn render(request, 'book_flight.html', {'flight': flight, 'error': 'No seats available.'})return render(request, 'book_flight.html', {'flight': flight})@login_required
def my_bookings(request):bookings = Booking.objects.filter(user=request.user)return render(request, 'my_bookings.html', {'bookings': bookings})def user_login(request):if request.method == 'POST':form = AuthenticationForm(request, data=request.POST)if form.is_valid():username = form.cleaned_data.get('username')password = form.cleaned_data.get('password')user = authenticate(username=username, password=password)if user is not None:login(request, user)return redirect('home')else:form = AuthenticationForm()return render(request, 'login.html', {'form': form})def user_signup(request):if request.method == 'POST':form = UserCreationForm(request.POST)if form.is_valid():user = form.save()login(request, user)return redirect('home')else:form = UserCreationForm()return render(request, 'signup.html', {'form': form})

Any idea what might be going wrong? I am skeptical about the placement of the templates folder, but changing that introduced the Template doesn't exist error.

main urls.py

from django.urls import path, include
from . import views
from django.contrib import admin
from django.views.generic.base import TemplateViewurlpatterns = [path(r'admin/',admin.site.urls),path('', views.home, name='home'),path('app/', include('app.urls')),path('',include('django.contrib.auth.urls')),path('',TemplateView.as_view(template_name='home.html'),name='home')]

Directory structure-

flight
└─ flight_booking├─ app│  ├─ admin.py│  ├─ apps.py│  ├─ migrations│  │  ├─ 0001_initial.py│  │  ├─ __init__.py│  │  └─ __pycache__│  │     ├─ 0001_initial.cpython-39.pyc│  │     └─ __init__.cpython-39.pyc│  ├─ models.py│  ├─ templates│  │  └─ app│  │     ├─ book_flight.html│  │     └─ search_fights.html│  ├─ tests.py│  ├─ urls.py│  ├─ views.py│  ├─ __init__.py│  └─ __pycache__│     ├─ admin.cpython-39.pyc│     ├─ apps.cpython-39.pyc│     ├─ forms.cpython-39.pyc│     ├─ models.cpython-39.pyc│     ├─ urls.cpython-39.pyc│     ├─ views.cpython-39.pyc│     └─ __init__.cpython-39.pyc├─ db.sqlite3├─ flight_booking│  ├─ asgi.py│  ├─ settings.py│  ├─ urls.py│  ├─ views.py│  ├─ wsgi.py│  ├─ __init__.py│  └─ __pycache__│     ├─ settings.cpython-39.pyc│     ├─ urls.cpython-39.pyc│     ├─ views.cpython-39.pyc│     ├─ wsgi.cpython-39.pyc│     └─ __init__.cpython-39.pyc├─ manage.py└─ templates├─ base.html├─ home.html└─ registration├─ login.html└─ signup.html
Answer

I don't think you are using the HTML files you actually created, try changing the return statement of your user_signup view to this:

return render(request, 'app/registration/signup.html', {'form': form})

https://en.xdnf.cn/q/118409.html

Related Q&A

tensorflow:Your input ran out of data when using custom generator

I am using custom generator to pass my data. But i keep encountering an error which says i have run out of data and to use repeat() when passing the dataset. i am using plain generator therefore it is …

script to get the max from column based on other column values

I need a script to read in a csv file(orig.csv) and output a reformatted csv file(format.csv) The orig csv file will look like this: Time,Label,frame,slot,SSN,Board,BT,SRN,LabelFrame,SRNAME,LabelID,Int…

Selenium code is not able to scrape ofashion.com.cn

I was building a web scraper by using python selenium. The script scraped sites like amazon, stack overflow and flipcart but wasnt able to scrape ofashion. It is always returning me a blank .csv file.H…

How can I access each estimater in scikit-learn pipelines? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

How do I structure a repo with Cloud Run needing higher level code?

I have added code to a repo to build a Cloud Run service. The structure is like this:I want to run b.py in cr. Is there any way I can deploy cr without just copying b.py into the cr directory? (I dont…

Unable to build kivy image loaded .py file into exe using auto-py-to-exe

I have a simple kivy file in which i want to cover the entire canvas with an image bgi.jpg MainWidget: <MainWidget>:canvas.before:Rectangle:size:self.sizesource:bgi.jpgand the .py file code i…

Pandas Panel is deprecated,

This code snippet is from one of my script which works fine in current panda version (0.23) but Panel is deprecated and will be removed in a future version.panel = pd.Panel(dict(df1=dataframe1,df2=data…

Python - Why is this data being written to file incorrectly?

Only the first result is being written to a csv, with one letter of the url per row. This is instead of all urls being written, one per row.What am I not doing right in the last section of this code t…

How does Python interpreter look for types? [duplicate]

This question already has answers here:How does Python interpreter work in dynamic typing?(3 answers)Closed 10 months ago.If I write something like:>>> a = float()how does Python interpreter …

title() method in python writing functions when word like arent

using functiondef make_cap(sentence):return sentence.title()tryining outmake_cap("hello world") Hello World# it workd but when I have world like "arent" and isnt". how to write…