Hola, soy principiante aprendiendo Django. Estoy tratando de seguir este tutorial:
https://docs.djangoproject.com/en/1.11/intro/tutorial01/
Creé una aplicación llamada Encuestas para probar mi sitio:
Como no tengo idea de dónde colocar el archivo llamado urls.py, coloco este archivo en los siguientes directorios:
Django/mysite/polls/urls.py Django/mysite/polls/migrations/urls.pyEste archivo contiene:
from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.index, name='index'), ]Y finalmente agregué las siguientes líneas:
en este nivel:
Django/mysite/mysite/urls.pyeste archivo contiene:
from django.conf.urls import include, url from django.contrib import admin from django.conf.urls import url from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^polls/', include('polls.urls')), ]No sé dónde está el problema, pero cuando ejecuto:
Django/mysite$ python3 manage.py runserver Performing system checks... System check identified no issues (0 silenced). You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. April 21, 2017 - 15:59:43 Django version 1.10.5, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.En la pagina tengo lo siguiente:
Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/ Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^admin/ ^polls/ The current URL, , didn't match any of these. You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.Así que realmente aprecio el apoyo para superar este problema, gracias por el apoyo.
el urls.py no va a la carpeta de migraciones.
¿Registraste tu aplicación Polls en el archivo settings.py? debe agregar el nombre de la aplicación Encuestas a la lista INSTALLED_APPS.
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'example: add app name here', 'polls',]luego debe crear un archivo url.py dentro de su aplicación de encuestas.
polls/ urls.pyEn ese archivo agregarías:
from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.index, name='index'), ]la URL que desea usar en su navegador sería algo como esto:
http://127.0.0.1:8000/polls