Yaaahhh

On Thu, 7 May 2020, 15:24 Daniel Roseman, <dan...@roseman.org.uk> wrote:

> You have multiple URLs that are the same path. That can't work. One URL
> maps to one view.
> --
> DR.
>
> On Thursday, 7 May 2020 11:40:09 UTC+1, Ronald Kamulegeya wrote:
>>
>> I am learning Django and progressing well but i am stuck on how to
>> configure the different urls to view functions.
>> I have gone through tutorials and URL routing seems pretty
>> straight forward but i cant make it work in my apps.
>>
>> I am almost hitting a brick wall. I dont see anything wrong i have done.
>>
>> What happens is that the index view and admin interface opens.
>>
>> But connecting from the index view to other pages raises the 404 error.
>>
>> [image: project-s.png]
>> I created a project TenancyMGt and added  app rentals as shown above.
>> I have created several views in the module views.py Two are relevant here:
>>
>> def createTenant(request):
>>     form = TenantsForm
>>     context = {'form': form}
>>     html_form = render_to_string('rentals/partial_tenant_create.html',
>>         context,
>>         request=request,
>>     )
>>     return JsonResponse({'html_form': html_form})class 
>> TenantsListView(ListView):
>>     model = Tenants
>>     context_object_name = 'tenant_list'
>>     template_name = 'rentals/tenants_list.html'
>>     paginate_by = 5
>>     def get_queryset(self):
>>         return Tenants.objects.all()
>>
>> Now i created a file urls.py under the app rentals:
>>
>> from . import viewsfrom django.urls import path
>> app_name='rentals'
>> urlpatterns = [
>>     path("", views.TenantsListView.as_view(), name="index"),
>>     path("",views.TenantDetailView.as_view,name="detail"),
>>     path("",views.createTenant, name='createTenant'),
>>     path("<int:pk>/",views.TenantUpdateView.as_view, name='edit'),
>>     path("<int:pk>/",views.delete, name='delete'),
>> ]
>>
>> under TenancyMgr/urls, i add the following:
>>
>> from django.contrib import adminfrom django.urls import path,includefrom 
>> rentals import views
>>
>> urlpatterns = [
>>     path('admin/', admin.site.urls),
>>     path('', include('rentals.urls')),
>> ]
>>
>> When i run the server, the index view opens successfully! From the index, i 
>> want to open the createTenant view as below.
>>
>> <button type="button" class="btn btn-primary js-create-tenant" data-url="{% 
>> url 'rentals:createTenant' %}>
>>       <span class="glyphicon glyphicon-plus"></span>
>>       New Tenant
>>     </button>
>>
>> When the button is clicked, i get the urls below:
>>
>> http://127.0.0.1:8000/rentals/createTenant/
>>
>> Then i get the response is 404,page not found error.
>>
>> But this opens admin page:
>>
>> http://127.0.0.1:8000/admin/
>>
>> So far i have failed to crack the secret of how the Urls work. I have gone 
>> through several tutorials and i see the same set up as mine.
>>
>> I am requesting for guidance on how to crack the puzzle i.e make the other 
>> urls work.
>>
>> Ronald
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4cc1d70b-119e-4f07-9867-f4c9786fbabc%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4cc1d70b-119e-4f07-9867-f4c9786fbabc%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKNQJk5xgmPLPA7-Drhtgc4andjuZ8yqh3sbAMaQ25zDATG-DA%40mail.gmail.com.

Reply via email to