url views problem

4 views
Skip to first unread message

sebastian stephenson

unread,
Jun 23, 2008, 9:22:06 AM6/23/08
to Django users
ok so I have in my data base a colium of rss feeds and I am parseing
them via feedparser and I am having a touble getting one feed to have
like "local/show/1" and another feed have "local/show/2" but how do
you do this here is the urls.py in its current state:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
# Example:
# (r'^ubermicro/', include('ubermicro.foo.urls')),

# Uncomment this for admin:
(r'^admin/', include('django.contrib.admin.urls')),
#temp only fo dev proposes
(r'^shows/','ubermicro.shows.views.show_page') # .* does not work
)


then views.py:

from django.http import HttpResponse
import feedparser
from ubermicro.shows.models import show
from django.template import Context, loader


def show_page(request):
"""this is where we take what we need form the rss feeds in the
data base"""
query = show.objects.filter(show_feed__contains="http://")
for s in query:
podcast = feedparser.parse(s.show_feed)
if podcast.entries:
elements = {'show_about':
podcast.feed.summary,'show_latest_title': podcast.entries
[0].title,'show_latest': podcast.entries[0].summary}
e = elements
t = loader.get_template('shows/show_page_base.html')
return HttpResponse(t.render(Context(e)))


just to say new to django and webdev python etc. so baby language
please thank you very much in advance


Thanks
see ya

sebey

phillc

unread,
Jun 23, 2008, 2:48:03 PM6/23/08
to Django users
http://www.djangoproject.com/documentation/url_dispatch/

look at the regular expressions used in the examples, and the section
"named groups"

sebey

unread,
Jun 24, 2008, 5:34:13 AM6/24/08
to Django users
cool thats great thanks anymore suggestions would be great thanks

sebey

unread,
Jun 24, 2008, 6:23:40 AM6/24/08
to Django users
I have gotten this traceback

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
site-packages/django/core/handlers/base.py" in get_response
68. callback, callback_args, callback_kwargs =
resolver.resolve(request.path)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
site-packages/django/core/urlresolvers.py" in resolve
160. for pattern in self.urlconf_module.urlpatterns:
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
site-packages/django/core/urlresolvers.py" in _get_urlconf_module
177. self._urlconf_module = __import__(self.urlconf_name, {}, {},
[''])
File "/Users/sebey/Sites/ubermicro/../ubermicro/urls.py" in
10. (r'^shows/(?p<show_feed>\d{1})/
s','ubermicro.shows.views.show_page') # .* does not work
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
site-packages/django/conf/urls/defaults.py" in patterns
18. pattern_list.append(RegexURLPattern(regex, prefix and (prefix +
'.' + view_or_include) or view_or_include, *default_kwargs))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
site-packages/django/core/urlresolvers.py" in __init__
96. self.regex = re.compile(regex)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
re.py" in compile
180. return _compile(pattern, flags)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
re.py" in _compile
233. raise error, v # invalid expression

error at /shows/1/
unexpected end of pattern


here is what I have done to the urls

from django.conf.urls.defaults import *

urlpatterns = patterns('',
# Example:
# (r'^ubermicro/', include('ubermicro.foo.urls')),

# Uncomment this for admin:
(r'^admin/', include('django.contrib.admin.urls')),
#temp only fo dev proposes
(r'^shows/(?p<show_feed>\d{1})/
s','ubermicro.shows.views.show_page') # .* does not work
)

can anyone help?

Tye

unread,
Jun 24, 2008, 6:46:21 AM6/24/08
to Django users
Why does the /shows/ etc url string end with

/s'

?

Typo?


Sent from my iPhone

Emil Styrke

unread,
Jun 24, 2008, 7:03:17 AM6/24/08
to django...@googlegroups.com


2008/6/24 sebey <se...@mac.com>:

   #temp only fo dev proposes
   (r'^shows/(?p<show_feed>\d{1})/
s','ubermicro.shows.views.show_page') # .* does not work
)

can anyone help?

You need to use a capital letter P: r'^shows/(?P<show_feed>\d{1})/'

  /Emil

sebey

unread,
Jun 24, 2008, 7:06:06 AM6/24/08
to Django users
ok fixed that yeah i saw that after I posted but here is what it looks
like now

from django.conf.urls.defaults import *

urlpatterns = patterns('',
# Example:
# (r'^ubermicro/', include('ubermicro.foo.urls')),

# Uncomment this for admin:
(r'^admin/', include('django.contrib.admin.urls')),
#temp only fo dev proposes
(r'^shows/(?p<show_feed>\d{1})/
$','ubermicro.shows.views.show_page')
)


thanks some please

sebey

unread,
Jun 24, 2008, 7:09:43 AM6/24/08
to Django users
it works but (thanks for the tips) it still is getting the same feed
for local/shows/1/ and local/show/2 help please

everyone who has helped so far thank you

Jeff FW

unread,
Jun 24, 2008, 8:44:09 AM6/24/08
to Django users
The regex you're using has a trailing /, so you need to have that in
your link as well:
/shows/1/

The other option is to make the trailing slash optional like so:
r'^shows/(?P<show_feed>\d{1})[/]?$'

sebey

unread,
Jun 24, 2008, 10:02:30 AM6/24/08
to Django users
either way its still the same thanks though but it still is not
working

phillc

unread,
Jun 24, 2008, 10:07:27 AM6/24/08
to Django users
you did not read
http://www.djangoproject.com/documentation/url_dispatch/

your method, show_page, is now passed a parameter called show_feed.
you need to use it accordingly

sebey

unread,
Jun 25, 2008, 4:58:43 AM6/25/08
to Django users
yes i have that set up it now looks like this


def show_page(request,show_feed):
"""this is where we take what we need form the rss feeds in the
data base"""
query = show.objects.filter(show_feed__contains="http://")
for s in query:
podcast = feedparser.parse(s.show_feed)
if podcast.entries:
elements = {'show_about':
podcast.feed.summary,'show_latest_title':
podcast.entries[0].title,'show_latest': podcast.entries[0].summary}
e = elements
t = loader.get_template('shows/show_page_base.html')
return HttpResponse(t.render(Context(e)))

but it still in not working so help please thank you for trying

On Jun 24, 3:07 pm, phillc <spyyd...@gmail.com> wrote:
> you did not readhttp://www.djangoproject.com/documentation/url_dispatch/

Jeff FW

unread,
Jun 25, 2008, 8:48:31 AM6/25/08
to Django users
You've now passed in the variable (which you can check by throwing a
"print show_feed" at the top of the function), but now you actually
need to *do* something with it. I'm assuming (not really knowing what
you want out of this) that you'd want to add an order_by clause to
order your podcasts (?) by *something*, then do some slicing to limit
the results.

Read:
http://www.djangoproject.com/documentation/db-api/#limiting-querysets

-Jeff

sebey

unread,
Jun 25, 2008, 9:17:33 AM6/25/08
to Django users

sorry but I do not want to limit the results as I am useing a parser
in the views.py but I want to get all of the urls and the first url
show/1, the second url I want to give shows/2 and so on and so on

Emil Styrke

unread,
Jun 26, 2008, 4:23:48 PM6/26/08
to django...@googlegroups.com
This line:


   query = show.objects.filter(show_feed__contains="http://")

selects all shows that have a feed url(?) containing "http://". The for loop then loops through these items and passes each one to feedparser. If you want to view only one show you have to change this to use the show ID you're passing in.  So maybe replacing the query line with

  s = show.objects.get(pk=show_feed)

and getting rid of the "for s in query" line might do the trick? Then you'll get only the feed for show 1 parsed when you go to /shows/1.

  /Emil

2008/6/25 sebey <se...@mac.com>:

sebey

unread,
Jul 1, 2008, 10:27:40 AM7/1/08
to Django users
cool sorry i will try that out sorry for replying so late but I will
post what the results are

thanks again
> ...
>
> read more »

sebey

unread,
Jul 2, 2008, 5:35:49 AM7/2/08
to Django users
wonderful!! its works thank you!!!
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages