1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Django: GET /getMessages// HTTP/1.1" 404 2987

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    I am following a Django tutorial video on how to create a simple chat room. When I want to create a new room, a pop-up alert says "An error occurred". Couldn't figure out what went wrong.

    Errors:

    home.html

    room.html

    urls.py

    from django.urls import path
    from . import views

    urlpatterns = [
    path('', views.home, name='home'),
    path('<str:room>/', views.room, name='room'),
    path('checkview', views.checkview, name='checkview')
    > ]


    views.py

    from django.shortcuts import render, redirect
    from chat.models import Room, Message

    # Create your views here.
    def home(request):
    return render(request, 'home.html')


    def room(request, room):
    return render(request, 'room.html')


    def checkview(request):
    room = request.POST['room_name']
    username = request.POST['username']

    if Room.objects.filter(name=room).exists():
    return redirect('/'+room+'/?username='+username)
    else:
    new_room = Room.objects.create(name=room)
    new_room.save()
    return redirect('/'+room+'/?username='+username)


    models.py

    from django.db import models
    from datetime import datetime


    # Create your models here.
    class Room(models.Model):
    name = models.CharField(max_length=1000)


    class Message(models.Model):
    value = models.CharField(max_length=1000000)
    date = models.DateTimeField(default=datetime.now, blank=True)
    user = models.CharField(max_length=1000000)
    room = models.CharField(max_length=1000000)

    Continue reading...

Compartilhe esta Página