How to make this code working django url path

83 Views Asked by At

My code is not working, and I am not sure why. I have the problem with hours_ahead function. Here is urlpatterns path('time/plus/(\d{1,2})/', hours_ahead), And I imported hours_ahead too

My code

1

There are 1 best solutions below

0
Bruno Gehlen On

One of these may work

In your urls.py add something like:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('hours/<int:offset>/', hours_ahead)
]

the "int:offset" is a way of saying what is the parameter you are going to receive and the type.

in settings.py add:

INSTALLED_APPS = [ # careful to not create another INSTALLED_APPS,add the app to the list! 
# ...
'playground' 

]

Also, I got this error on my terminal:

CommandError: 'playgrounds' conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name.

I could not run the code until I created and app with another name.