django-urls

My Django URLs not picking up dashes

◇◆丶佛笑我妖孽 提交于 2019-12-02 23:36:06
Im trying to work out a url that will match domain.com\about-us\ & domain.com\home\ I have a url regex: ^(?P<page>\w+)/$ but it won't match the url with the - in it. I've tried ^(?P<page>\.)/$ ^(?P<page>\*)/$ but nothing seems to work. Try: ^(?P<page>[-\w]+)/$ [-\w] will accept a-z 1-9 and dash 来源: https://stackoverflow.com/questions/531243/my-django-urls-not-picking-up-dashes

Django and urls.py: How do I HttpResponseRedirect via a named url?

試著忘記壹切 提交于 2019-12-02 22:07:27
I'm writing a member-based web application, and I need to be able to redirect the page after login. I want to use the named url from my urls.py script in my views.py file for the login application, but I can't for the life of me figure out what to do. What I have is this: def login(request): if request.session.has_key('user'): if request.session['user'] is not None: return HttpResponseRedirect('/path/to/page.html') What I want to accomplish is something like: def login(request): if request.session.has_key('user'): if request.session['user'] is not None: return HttpResponseRedirect url pageName

How to use namespace urls with django in a reusuable app

旧时模样 提交于 2019-12-02 20:27:57
I have a django app, a forum app, that has templates with it. In those templates, there are urls that point to parts of the app. For instance the thread_list template has links to each thread like so: {% for thread in threads %} <a href="{% url forum_thread thread %}">{{thread.title}}</a> {% endfor %} The thing is, I don't really like calling my urls "forum_thread". I prefer just "thread" and using the namespace feature of django. "forum_thread" may be used somewhere else in the project (namespace collision).So it will look like this: {% for thread in threads %} <a href="{% url forum:thread

How to do reverse URL search in Django namespaced reusable application

旧时模样 提交于 2019-12-02 18:35:20
Consider that I include namespaced reusable application: urlpatterns = patterns('', # ella urls url('^ella/', include('ella.core.urls', namespace="ella")), ) Now, the Ella applications has urls like that: urlpatterns = patterns( '', url( r'^(?P<category>[a-z0-9-/]+)/$', category_detail, name="category_detail" ), # object detail url( r'^(?P<category>[a-z0-9-/]+)/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<content_type>[a-z0-9-]+)/(?P<slug>[a-z0-9-]+)/$', object_detail, name="object_detail" ) ) Now, calling {% url ella:category_detail category="cat" %} works fine. However, when

Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/

最后都变了- 提交于 2019-12-02 16:26:44
问题 I was following the django documentation and making a simple poll app. I have come across the following error : Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^polls/ ^admin/ The current URL, , didn't match any of these." settings.py ROOT_URLCONF = 'mysite.urls' mysite/mysite/urls.py from django.conf.urls import include,url from django.contrib import admin urlpatterns = [ url(r'^polls/',include('polls.urls')), url(r'^admin/', admin.site.urls),]

How do I unit test django urls?

你离开我真会死。 提交于 2019-12-02 15:27:47
I have achieved 100% test coverage in my application everywhere except my urls.py . Do you have any recommendations for how I could write meaningful unit tests for my URLs? FWIW This question has arisen as I am experimenting with Test-Driven Development and want failing tests before I write code to fix them. karthikr One way would be to reverse URL names and validate Example urlpatterns = [ url(r'^archive/(\d{4})/$', archive, name="archive"), url(r'^archive-summary/(\d{4})/$', archive, name="archive-summary"), ] Now, in the test from django.urls import reverse url = reverse('archive', args=

Django URLS, how to map root to app?

*爱你&永不变心* 提交于 2019-12-02 14:50:47
I am pretty new to django but experienced in Python and java web programming with different frameworks. I have made myself a nice little django app, but I cant seem to make it match www.mysite.com as opposed to www.mysite.com/myapp. I have defined urls and views in my urls.conf which is currently not decoupled from the app (don't mind that). urlpatterns = patterns('myapp.views', (r'^myapp/$', 'index'), (r'^myapp/(?P<some_id>\d+)/global_stats/$', 'global_stats'), (r'^myapp/(?P<some_id>\d+)/player/(?P<player_id>\d+)/$', 'player_stats'), ) All this works like a charm. If someone goes to www

Using object's id in change_form_object_tools.html template

末鹿安然 提交于 2019-12-02 13:19:55
I have two buttons that appointing to different paths. And i want to pass the object.id with parameter. my urls urlpatterns = [ path('', admin.site.urls, name ='home'), path('dpo/imprimir/aprovado/<int:id>/',Aprovado, name ='aprovado'), path('dpo/imprimir/reprovado/<int:id>/',Reprovado, name ='reprovado'), ] My views from django.http import HttpResponse from django.shortcuts import render from django.shortcuts import render_to_response from .models import Projeto def Aprovado(request, id): obj = Projeto.objects.get(id=id) context = { "object": obj } return render(request, "dpo/imprimir

Django: UnboundLocalError: local variable 'company' referenced before assignment

百般思念 提交于 2019-12-02 12:29:17
问题 I am trying to make a url field in my detail view by passing two primary key in it... This is what I have done in urls.py: url(r'^company/(?P<pk1>\d+)/groupdetail/(?P<pk2>\d+)/$',views.group1DetailView.as_view(),name='groupdetail'), And in my views: def get_object(self): pk1 = self.kwargs['pk1'] pk2 = self.kwargs['pk2'] company = get_object_or_404(company, pk=pk1) group1 = get_object_or_404(group1, pk=pk2) return group1 I am getting error in this line: company = get_object_or_404(company, pk

Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/

旧巷老猫 提交于 2019-12-02 10:04:26
I was following the django documentation and making a simple poll app. I have come across the following error : Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^polls/ ^admin/ The current URL, , didn't match any of these." settings.py ROOT_URLCONF = 'mysite.urls' mysite/mysite/urls.py from django.conf.urls import include,url from django.contrib import admin urlpatterns = [ url(r'^polls/',include('polls.urls')), url(r'^admin/', admin.site.urls),] mysite/polls/urls.py from django.conf.urls import url from . import views app_name= 'polls' urlpatterns=[