0

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

Mangi
  • 23
  • 6
  • could you elaborate a bit what "my code is not working" means? What is the issue you are experiencing? – burnedikt Feb 11 '23 at 21:44
  • It means that when i go to http://127.0.0.1:8000/time/plus/3/ it shows me page not found. And the thing is that i wanted to make dynamic code that can show time and in the same time i dont need to make new paths for every hour it resets. I think that the problem is in this part of the code path('time/plus/(\d{1,2})/', hours_ahead), I want this url to me dynamic – Mangi Feb 11 '23 at 21:48
  • You can use `path('time/plus//', hours_ahead)` – kamran890 Feb 11 '23 at 22:05
  • 1
    what version of django are you using? It appears like your url path contains a regex but path no longer supports regexs since [version 2.0](https://docs.djangoproject.com/en/2.0/topics/http/urls/#using-regular-expressions). So you'd need to use `re_path('time/plus/(\d{1,2})/')` instead. – burnedikt Feb 11 '23 at 22:06
  • Sir, Can you explain me this part of the code, or give me some resource to study it a little? – Mangi Feb 11 '23 at 22:17

1 Answers1

1

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.