how to use rest_framework.urls, through /login/ - django

i wanna make my own API through rest_framework.urls (/login/)=> i think /login/ url is provided by this framework.
enter image description here
as you can see, i wrote my client type of json, but i think that key:values are not "email" and "password".
plz let me know the json type when using rest_framework.urls (/login/)
Thank you
# apps.urls.py
urlpatterns = [
path('signup/', UserCreate.as_view()),
**path('', include('rest_framework.urls')),**
]
# project(root).urls.py
urlpatterns = [
path('admin/', admin.site.urls),
**path('login/', include('login.urls')),**
path('', include('postapp.urls')),
]
i want to enter my client to that page(rest_framework/login/) by using json type

Related

Django urldispatcher: directing the request to special view

Django=3.0.8
urls.py
urlpatterns += [
path('<slug:categories>/', include('categories.urls', namespace="categories")),
]
categories/urls.py
urlpatterns = [
path('', CategoryGeneralView.as_view(), name='general'),
re_path(r'^(?P<type>novosti|tema)$/',CategorySpecialView.as_view(), name="type"),
path('draft/<slug:slug>/', PostDetailView.as_view(), name="draft_post_detail"),
path('<slug:slug>/', PostDetailView.as_view(), name="post_detail"),
]
Problem
When I input either of
http://localhost:8000/windows/tema/
http://localhost:8000/windows/novosti/
the request goes to PostDetailView. But I want it to go to CategorySpecialView.
How can I achieve this?
Why not just use 2 separate paths, i.e.:
path('novosti/', CategorySpecialView.as_view(), name = 'type'),
path('tema/', CategorySpecialView.as_view(), name = 'type'),

Router not displaying correct URL in Django RestFramework?

This is how I defined urls.py file of my app
router = DefaultRouter()
router.register('hello-viewset', views.HelloViewSet, base_name='hello-viewset')
router.register('profiles', views.UserProfileViewSet)
router.register('schema', views.SchemaViewSet)
router.register('creddefination', views.CredDefViewSet)
router.register('overalltable', views.OverallViewSet)
urlpatterns = [
path('', include(router.urls)),
]
urls.py of Project:
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('DIAPI.urls')),
]
I am not getting correct address for creddefination. But when i manually go to http://127.0.0.1:7000/api/creddefination/ it is working. It is just not displaying correctly. What might be reason for this
I guess views.CredDefViewSet and views.OverallViewSet are using the same model.
If that's true, then the default register's basename will be named after that model and used as name in a call to Django's reverse url construction. Since the API Root view will be trying to resolve both views with the same name, it'll lead to the same url.
Workaround is to explicitly add a basename to one of the view:
router.register('creddefination', views.CredDefViewSet, basename='creddeef')

Django url/route order not maintained

I have the following in my root URLconf module (there's more, but not important, so left out):
urlpatterns = [
re_path(r'^password-reset-redirect-view/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
password_reset_redirect,
name = 'password_reset_confirm'),
path('', include('search.urls')),
path('', include('customer_portal.urls')),
path('rest-auth/', include('rest_auth.urls')),
path('rest-auth/registration/', include('rest_auth.registration.urls')),
Here's the customer_portal.urls:
urlpatterns = [
path('customer/contact/', views.contact),
path('', views.home),
re_path(r"^confirm-email/(?P<key>[-:\w]+)/$", views.email_verification,
name="account_confirm_email"),
]
Here's the rest_auth.registration.urls:
urlpatterns = [
url(r'^$', RegisterView.as_view(), name='rest_register'),
url(r'^verify-email/$', VerifyEmailView.as_view(), name='rest_verify_email'),
url(r'^account-confirm-email/(?P<key>[-:\w]+)/$', TemplateView.as_view(),
name='account_confirm_email'),
]
As you can see both included urls.py urlpatterns have a view named 'account_confirm_email'.
Somewhere in the code this is ran:
url = reverse(
"account_confirm_email",
args=[emailconfirmation.key])
Since customer_portal.urls is included before rest_auth.registration.urls, I expect the route account_confirm_email in customer_portal.urls to be returned by the above reverse method. But instead I get the rest_auth.registration.urls route URL.
Just to be sure I commented out the route in rest_auth.registration.urls, and then I did get the correct URL (customer_portal URL) returned.
It is filled into an email, I check that email and see that I have the wanted url: http://127.0.0.1:8000/confirm-email/......./, instead of: http://127.0.0.1:8000/rest-auth/registration/account-confirm-email/...../
Can anyone tell me why the customer_portal URL isn't the one being reversed in both cases?
Django docs say:
Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL.

Page not found error happens-Can <str:id> be used?

Page not found error happens-Can be used?
I wrote in urls.py
from django.conf.urls import url
from app import views
urlpatterns = [
url('^data/<str:id>', views.data, name='data'),
]
in views.py
def data(id):
・
・
・
return None
For example, when I access http://127.0.0.1:8000/data/AD04958 ,
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/data/AD04958
error happens.
I think I can write this url http://127.0.0.1:8000/data/AD04958 into '^data/' in urls.py,so I really cannot understand why this error happens. id is not save in Database,does it cause this error?
What is wrong in my codes?How should I fix this?
For Django<=1.11.x
urlpatterns = [
url(r'^data/(?P<id>[\w.-]+)/$', views.data, name='data'),
]
For Django>=2
urlpatterns = [
path('^data/<str:id>', views.data, name='data'),
]

Reverse for 'account_email_verification_sent' not found. 'account_email_verification_sent' is not a valid view function or pattern name

I'm trying to use allauth and rest-auth in my project and try to use the built-in function in allauth to do email verification but this what I get :
and here is my code
settings.py
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_EMAIL_REQUIRED = True
urls.py
urlpatterns = [
re_path(r'^', include('rest_auth.urls')),
re_path(r'^registration/', include('rest_auth.registration.urls')),
]
I found the solution, that I have to add URL to be able to make a post request to the backend to send email then URL with regex which has the token that will verify the account and URLs and add URL for login with name account_login and URL for register with name account_signup and be like this :
from rest_auth.registration.views import VerifyEmailView, RegisterView
urlpatterns = [
path('', include('rest_auth.urls')),
path('login/', LoginView.as_view(), name='account_login'),
path('registration/', include('rest_auth.registration.urls')),
path('registration/', RegisterView.as_view(), name='account_signup'),
re_path(r'^account-confirm-email/', VerifyEmailView.as_view(),
name='account_email_verification_sent'),
re_path(r'^account-confirm-email/(?P<key>[-:\w]+)/$', VerifyEmailView.as_view(),
name='account_confirm_email'),
]
I had the same issue but I already had set up the URL for the email confirmation but I forgot about the name parameter it is mandatory
from django.conf.urls import url, include
from dj_rest_auth.registration.views import VerifyEmailView
urlpatterns = [
url('auth/', include('dj_rest_auth.urls')),
url('auth/registration/', include('dj_rest_auth.registration.urls')),
url('auth/account-confirm-email/', VerifyEmailView.as_view(), name='account_email_verification_sent'),
]
´´´