Reputation: 177
I am trying to use keywords in my Django URl but it will not allow me. I have tried the syntax of about 7-8 peoples projects and none of them have worked...
So basically I have a class with user info and one of the attributes it contains is "first_name", obviously representing the first name of the users in the database.
So basically, according to my app, userData/index : brings up a list of all users userData/1 : brings up the info of the user with the ID of 1
The code for this is...
urlpatterns = [
path('admin/', admin.site.urls),
path('', welcome),
path('userData/', include('userData.urls')),
]
This is the code from my project url folder^
from django.conf.urls import url
from .views import admins, index, ratings
urlpatterns = [
url('admins', admins, name='admins'),
url('index/', index, name='index'),
url('user_id', ratings, name='rating')
]
Now here is where the problem is, the keyword user_id simply prints literally the characters user_id as a string in the url bar when I want it to print the user id.
I just dont know what to write in place of 'user_id'.. Any help is appreciated, thank you!
Upvotes: 0
Views: 389
Reputation: 2159
change your project url from
from django.conf.urls import url
from .views import admins, index, ratings
urlpatterns = [
url('admins', admins, name='admins'),
url('index/', index, name='index'),
url('user_id', ratings, name='rating')
]
to
from django.urls import include, path
from .views import admins, index, ratings
urlpatterns = [
path('admins', admins, name='admins'),
path('index/', index, name='index'),
path('<int:pk>/', ratings, name='rating')
]
Upvotes: 1