Estoy configurando un nuevo sitio web de "Juego". Comencé una nueva aplicación Juegos, configuré juegos/modelos.py con el código (a continuación). Después de hacer el juego de migraciones y migrar, pude iniciar sesión en Admin y agregar entradas.
Luego me puse a crear las URL, las vistas, una plantilla. Después de crearlos, cuando ejecuto el servidor, aparece el siguiente error:
url_patterns plantean ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e django.core.exceptions.ImproperlyConfigured: The URLconf '<module 'games.urls' incluido de '/home/mackley/PycharmProjects/alphabet/games/urls .py'>' no parece tener ningún patrón. Si ve patrones válidos en el archivo, es probable que el problema se deba a una importación circular.
Lo primero que noté es que la línea superior ( desde la configuración de importación de django.conf ) de games/models.py (usando PyCharm) está atenuada. No sé si eso tiene algo que ver con el error:
¿Alguien puede detectar dónde he cometido un error? Aquí está el código correspondiente.
# games/models.py from django.conf import settings from django.contrib.auth import get_user_model from django.db import models from django.urls import reverse class Game(models.Model): title = models.CharField(max_length=255) date_create = models.DateTimeField(auto_now_add=True) date_start = models.DateTimeField(auto_now_add=False) body = models.TextField() author = models.ForeignKey( get_user_model(), on_delete=models.CASCADE, ) answer_one = models.CharField(max_length=1) answer_two = models.CharField(max_length=1) answer_three = models.CharField(max_length=1) answer_four = models.CharField(max_length=1) answer_five = models.CharField(max_length=1) answer_six = models.CharField(max_length=1) answer_seven = models.CharField(max_length=1) payout_total = models.FloatField(null=True, blank=True, default=1.0) def __str__(self): return self.title def get_absolute_url(self): return reverse('game_detail', args=[str(self.id)])juegos/administrador
# games/admin.py from django.contrib import admin from .models import Game admin.site.register(Game)configuración/URL
# config/urls.py from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('accounts/', include('accounts.urls')), path('accounts/', include('django.contrib.auth.urls')), path('games/', include('games.urls')), path('', include('pages.urls')), ]juegos/url
# games/urls.py from django.urls import path from .views import GameListView urlpattrns = [ path('', GameListView.as_view(), name='game_list'), ]juegos/vistas.py
# games/views.py from django.views.generic import ListView from .models import Game class GameListView(ListView): template_name = 'game_list.html'Como indica el error, esto sucede cuando django no puede encontrar patrones de URL válidos en su urlconf. Puede haber muchas razones para esto, pero la que me parece más probable en su caso es que urlpatterns esté mal escrito como 'urlpattrns' en games/urls.py. Intente corregir el error tipográfico y vuelva a ejecutar.