I started working on django ( read the django documentation and several youtube tutorials )
I dont understand what is wrong , the editor is not showing any errors ( VSCode ).
When I start the server it is showing me the default rocket icon ....I have tried reinstalling django but it also didnt help....also restarted the server several times.
I am stuck right now.
main url file
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('calc/',include('calc.urls')),
path('admin/', admin.site.urls),
]
url file for the app (calc)
from django.urls import path
from . import views
urlpatterns = [
path('',views.index,name='index')
]
views file for the app
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home(request):
return HttpResponse("Hello World")
edit url path in calc app to the below.
path('', views.home ,name='index')
Related
I am writing basic views and then putting it in urls.py but it is still not working.
views.py
from django.http import HttpResponse
def home(request):
return HttpResponse("hello how are you")
project urls.py
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('blog.urls')),
]
blog/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('home/',views.home,name='home')
]
I have also included my app in settings of project (Installed apps).
Some thoughts about that:
Change your urls patterns in your apps urls to:
from .views import *
urlpatterns= [
path('', home,name='home')
]
If its not working send us your installed apps settings and wsgi file
You confused, you need to write http://127.0.0.1:8000/home not only http://127.0.0.1:8000 with your current code.
If you want the view to be rendered in default route so change urls.py as:
from . import views
urlpatterns= [
path('', views.home,name='home')
]
Otherwise, you can only append /home with your current code to work.
for the same code above it is working for the URL http://127.0.0.1:8000/home/
I am starting my first django application. I constantly keep getting 404 error after turning on server locally in my computer. I don't see any reason for such return because urls seem to be correct when compared to tutorials and guides on the internet.
This is my urls file inside app (app name is reservations)
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index')
]
This is urls file in project folder (project name is website)
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('reservations/', include('reservations.urls'))
]
and this is index function which is supposed to show basic html
def index(request):
response = """<html><body><p>This is home page</p></body></html>"""
return HttpResponse(response)
I thought that my urls are written incorrectly so i tried writing them in different way but it never worked. Thanks for any help.
I'm developing my first app in Django and facing some issues. The server runs smoothly and I can operate the admin panel without any issues.
However, all of the app pages including the default homepage show a "404 not found" error.
I have created a templates directory in project root
updated this line in settings.py for templates,
'DIRS': [os.path.join(BASE_DIR,'templates')],
View for the app
from django.shortcuts import render
from .models import *
# Create your views here.
def customers(request):
customers = Customer.objects.all()
return render(request, "customers.html", {'customers': customers})
urls for the app
from django.urls import path from . import views
urlpatterns = [path('customers',views.customers, name='customers')]
urls for the project
from django.contrib import admin from django.urls import path, include from django.conf import settings from django.conf.urls.static import static
urlpatterns = [
path('trips/',include('trips.urls')),
path('customers/',include('customers.urls')),
path('drivers/',include('drivers.urls')),
path('vehicles/',include('vehicles.urls')),
path('admin/', admin.site.urls), ]
urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Help is appreciated
I can't see any problem with your case, you should be able to load http://localhost:8000/customers/customers. Maybe double customers was not you intention, then remove one of them (one in main urls.py one in app's).
Also when Django debug mode is active and you get a 404 because of URL mismatch, it shows you a list of URLs you have. To see it navigate to a non existing URL like http://localhost:8000/aaa. Then if you see customers/ there try http://localhost:8000/customers/. Go step by step to find the problem.
I have searched endlessly for a solution and I can't seem to find it, even though I know this has been asked before. I am encountering a perpetual 404 error from the django tutorial. It appears to me that the 'urlpatterns' isn't recognizing another option of than admin.
backend/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('test/', include('meat.urls')),
path('admin/', include(admin.site.urls)),
]
backend/meat/urls.py
from django.contrib import admin
from django.urls import path, include
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
backend/meat/views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(requests):
return HttpResponse('Hello Wold')
In order to access views inside the meat app.
you have included the urls of meat to the test/ path.
Thus you should use url /test/
if you are developing on local host then localhost:8000/test/
NB: I have tested this right now link
PS: try changing the path of admin site to path('admin/', admin.site.urls),
I was recently building a django project. I have been looking through the files for a couple of hours now and can't find the problem that would result in this kind of error message. Below, I will show you all of the relevant files within the project.
base url.py:
from django.conf.urls import url,include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^display/', include('diplay.urls')),
]
app url.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
app views.py:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("<h2>HEY!</h2>")
I'm not sure why this is not working because I found a similar format online, and it seemed that every line was similar to the other one. When I try running the server, it gives me the error statement
ImportError: No module named diplay.urls
Any ideas?
1, make sure your app name is diplay which is same as in your base urls.py, I think maybe there is typo, should change to:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^display/', include('display.urls')),
]
2, make sure the file name of urls should be urls.py instead of url.py in both base and app folder
Does app diplay exists or is it typo of display
> diplay.urls
Also does urls file in app exists