V
V
val1n0r2020-02-25 20:07:30
Django
val1n0r, 2020-02-25 20:07:30

How to resolve django url conflict?

Ku
Is urls.py

urlpatterns = [
    path('', EquipPage.as_view(), name = 'EquipPage'),
    path('helmets/',UserInventoryHelmet.as_view(),name='InvHelmet'),
    path('<str:inv_helmet_unique_id>',SetNewHelm.as_view(),name='equipHelmet'),

    path('gloves/',UserInventoryGlove.as_view(),name='InventGlove'),
    path('<str:inv_glove_unique_id>/',SetNewGlove.as_view(),name='EquipGlove'),

    path('pants/', UserInventPants.as_view(), name='InvPants'),
    path('<str:inv_torso_unique_id>/',SetNewPants.as_view(),name='EquipTorso'),

    path('chests/',UserInventoryChest.as_view(),name='InvChest'),
    path('<str:inv_armour_unique_id>/',SetNewChest.as_view(),name='EquipBodyArmour'),
    

    
]


There is such a view, or rather several of them

class UserInventoryHelmet(UserInfo,View):
    def get(self, request, *args, **kwargs):
        uid = request.user.id
        logic_data = super(UserInventoryHelmet, self)
        context = {}
        user_stat_list = logic_data.UserStat(uid)
        context = user_stat_list
        context['active_helmet'] = UserHelmet.objects.filter(user_helmet_id=uid)
        context['invent_helmet'] = UserInvHelmet.objects.filter(inv_helmet_id=uid)
        return render(request,'equip/helmets.html',context)


class SetNewHelm(EqHelmet,UserInfo,View):
    def post(self,request,inv_helmet_unique_id,*args,**kwargs):
        uid = request.user.id
        if request.method == "POST":
            logic_data = super(SetNewHelm, self)
            is_h_eq = logic_data.set_new_helm(uid,inv_helmet_unique_id)
            if is_h_eq:
                messages.add_message(request, messages.INFO, "Надели шлем")
                return redirect('EquipPage')  
            else:
                messages.add_message(request, messages.INFO, "Этого предмета не существует")
                return redirect('EquipPage')

When following a link, for example, path('helmets/',UserInventoryHelmet.as_view(),name='InvHelmet'), I
get - HTTP ERROR 405

I have a get in the first view, as in others

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2020-03-06
@tumbler

Remove extra routes in urls.py, perhaps after that the request will still get into your UserInvertoryHelmet. So far, it seems that it falls into one of the SetXXX.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question