django-urls

Passing a list through url in django

纵然是瞬间 提交于 2019-12-01 12:56:22
问题 I want to pass a list through the url. But when i tried, i got some errors. So how can i do that. Somebody please help me.. this is my view def add_student(request): if request.method == 'POST': student_list = [] student_name = request.POST.getlist('student_name') student_phone = request.POST.getlist('student_phone') zipped = zip(student_name,student_phone) for student_name,student_phone in zipped: student_object = Student( student_name=student_name, student_phone=student_phone ) student

Understanding django.shortcuts.redirect

不打扰是莪最后的温柔 提交于 2019-12-01 11:14:24
I have a couple problems understanding how redirect or rather reverse really work. In the main urls.py I have: from django.conf.urls import patterns, include, url from django.views.generic.simple import redirect_to urlpatterns = patterns('', url(r'^$', redirect_to, {'url': '/monitor/'}), url(r'^monitor/', include('monitor.urls')), ) and in monitors.urls I have: from django.conf.urls import patterns, include, url urlpatterns = patterns('monitor.views', (r'^$', 'index'), (r'^abc/(?P<id>.*$)', 'abc'), ) When you call /monitor I want to redirect it to /monitor/abc so I did: def index(request):

Facing problem with user profile url scheme like example.com/username in django

℡╲_俬逩灬. 提交于 2019-12-01 10:52:38
In a django app, I need to create twitter user profile urls with following structure like: example.com/<username> example.com/<username>/friends example.com/<username>/blog example.com/<username>/some-page example.com/<username>/some-other-page My urls.py: urlpatterns = patterns('profiles.views', url(r'^(?P<account_name>[a-zA-Z0-0_.-]+)/$', 'show_profile', name='profiles_show_profile'), url(r'^(?P<account_name>[a-zA-Z0-0_.-]+)/friends/$', 'show_friends', name='profiles_show_blog'), url(r'^(?P<account_name>[a-zA-Z0-0_.-]+)/blog/$', 'show_blog', name='profiles_show_blog'), ) My first problem is

Understanding django.shortcuts.redirect

泄露秘密 提交于 2019-12-01 09:54:20
问题 I have a couple problems understanding how redirect or rather reverse really work. In the main urls.py I have: from django.conf.urls import patterns, include, url from django.views.generic.simple import redirect_to urlpatterns = patterns('', url(r'^$', redirect_to, {'url': '/monitor/'}), url(r'^monitor/', include('monitor.urls')), ) and in monitors.urls I have: from django.conf.urls import patterns, include, url urlpatterns = patterns('monitor.views', (r'^$', 'index'), (r'^abc/(?P<id>.*$)',

How do I redirect by URL pattern in Django?

穿精又带淫゛_ 提交于 2019-12-01 05:27:39
I have a Django based website. I would like to redirect URLs with the pattern servertest in them to the same URL except servertest should be replaced by server-test . So for example the following URLs would be mapped be redirected as shown below: http://acme.com/servertest/ => http://acme.com/server-test/ http://acme.com/servertest/www.example.com => http://acme.com/server-test/www.example.com http://acme.com/servertest/www.example.com:8833 => http://acme.com/server-test/www.example.com:8833 I can get the first example working using the following line in urls.py: ('^servertest/$', 'redirect_to

How Do I Use A Decimal Number In A Django URL Pattern?

回眸只為那壹抹淺笑 提交于 2019-12-01 03:48:45
I'd like to use a number with a decimal point in a Django URL pattern but I'm not sure whether it's actually possible (I'm not a regex expert). Here's what I want to use for URLs: /item/value/0.01 /item/value/0.05 Those URLs would show items valued at $0.01 or $0.05. Sure, I could take the easy way out and pass the value in cents so it would be /item/value/1, but I'd like to receive the argument in my view as a decimal data type rather than as an integer (and I may have to deal with fractions of a cent at some point). Is it possible to write a regex in a Django URL pattern that will handle

django template extends not working

本小妞迷上赌 提交于 2019-11-30 23:13:21
问题 This is my base.html <!DOCTYPE html> <head> <title> My Site </title> </head> <body> <div id="wrapper"> <!-- HEADER START --> {% block nav %} {% endblock %} {% block index %} {% endblock %} </div> </body> </html> this is my nav.html {% extends "base.html" %} {% block nav %} <div id="header"> <div class="inner"> <div class="nav"> <ul> <li class="current"><a href="index.html">Home</a></li> <li><a href="about.html">About</a></li> <li><a href="blog_right.html">Blog</a></li> <li><a href="contact

How to redirect url pattern with variables from urls.py in Django?

百般思念 提交于 2019-11-30 19:12:47
I'd like to redirect url pattern with variables from urls.py . I refer other stackoverflow solution , but I don't know when url having a variable like following code. from django.conf.urls import patterns, url from django.views.generic import RedirectView urlpatterns = patterns( url( r'^permalink/(?P<id>\d+)/foo/$', RedirectView.as_view(url='/permalink/(?P<id>\d+)/') ), ) With this code, django will redirect /permalink/1/foo/ to /permalink/(?P<id>\d+)/ , not the /permalink/1/ . Is there any solution without using views.py ? Of course I know solution using controller, but I wonder is there any

Django: Slug in Vietnamese

混江龙づ霸主 提交于 2019-11-30 15:22:18
A site in Vietnamese, it is virtually no different to English. However, there is a problem that is slug. When I type characters such as "ư", "ơ", "á",... Django is not identified. Solution here is to replace characters that do not sign into. Eg: ư -> u ơ -> o á -> a One from "những-viên-kẹo" will become "nhung-vien-keo". However, I do not know how to do this. Someone help me. Thank you very much! [edit] I take it back, django's django.template.defaultfilters.slugify() does what you want, using unicodedata.normalize and .encode('ascii', 'ignore') . Just feeding your string into slugify will

Django HttpResponseRedirect

痴心易碎 提交于 2019-11-30 11:18:47
I have created a basic contact form, and when the user submits information, it should redirect to the "Thank You" page. views.py : def contact(request): # if no errors... return HttpResponseRedirect('/thanks/') urls.py : (r'^contact/$', contact), (r'^contact/thanks/$', contact_thanks), Both pages work at the hard-coded URL. However, when I submit the form on /contact/ it redirects to /contact (no ending slash), which is a nonexistent page (either a 404 or an error page telling me I need a slash). What is the reason it not correctly redirecting, and how can I fix this? UPDATE: the return