Ver Mensaje Individual
  #4 (permalink)  
Antiguo 18/12/2012, 20:18
minimal
 
Fecha de Ingreso: diciembre-2011
Mensajes: 408
Antigüedad: 13 años
Puntos: 18
Respuesta: django urls por base de datos

aca un ejemplo de mi urls.py deberia funcionar pero no funciona cuando actualizo la base de datos
Código Python:
Ver original
  1. #encoding:utf-8
  2. from django.conf.urls import patterns, include, url
  3. import os,sys
  4. # Uncomment the next two lines to enable the admin:
  5. from django.conf import settings
  6. from django.contrib import admin
  7. from catalogo.models import Categories,Product
  8. from html.models import Page
  9. sys.dont_write_bytecode = True
  10. def fromRelativePath(*relativeComponents):
  11.     RUTA_PROYECTO = os.path.dirname(os.path.realpath(__file__))
  12.     return os.path.join(RUTA_PROYECTO, *relativeComponents).replace("\\","/")
  13.  
  14. def add_catalog_product_url(urlpatterns):
  15.     for product in Product.get_all_products():
  16.         slug= r'^catalogo/detalle/%s' % product.slug
  17.         item= url(slug, 'catalogo.views.product_detail')
  18.         urlpatterns += patterns('',item)
  19. def add_catalog_categories_url(urlpatterns):
  20.     for category in Categories.get_all_categories():
  21.         slug= r'^catalogo/%s' % category.slug
  22.         item= url(slug, 'catalogo.views.catalog')
  23.         urlpatterns += patterns('',item)
  24.     for category in Categories.list_categories():
  25.         sub_slug= r'^catalogo/%s/%s' % (category.parent.slug,category.slug)
  26.         sub_item= url(sub_slug, 'catalogo.views.sub_catalog')
  27.         urlpatterns += patterns('',sub_item)
  28.  
  29.  
  30. def add_html_page_url(urlpatterns):
  31.     for thepage in Page.get_all_pages():
  32.         slug= r'^%s' % thepage.slug
  33.         item= url(slug, 'html.views.list_the_page',name=thepage.slug)
  34.         urlpatterns += patterns('',item)
  35.  
  36. admin.autodiscover()
  37.  
  38. urlpatterns = patterns('',
  39.     # Examples:
  40.     url(r'^$', 'catalogo.views.home', name='home'),
  41.  
  42.     url(r'^catalogo/search$', 'catalogo.views.catalog_search', name='catalog_search'),
  43.     url(r'^contacto$', 'html.views.contact_form', name='contact_form'),
  44.     url(r'^process/contact$', 'html.views.process_contact', name='process_contact_form'),
  45.     #url(r'^zandalia-larga', 'catalogo.views.home', name='home2'),
  46.     #url(r'^catalogo/(?P<slug>)', 'catalogo.views.catalog', name='catalog'),
  47.     # url(r'^mysite/', include('mysite.foo.urls')),
  48.     # url(r'^lista/$', 'backend.views.lista_groups'),
  49.     (r'^js/(?P<path>.*)$', 'django.views.static.serve', {'document_root':fromRelativePath('../design/static')}),
  50.     (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root':fromRelativePath('../media')}),
  51.     (r'^admins/(?P<path>.*)$', 'django.views.static.serve', {'document_root':fromRelativePath('../design/static/admins'), 'show_indexes': True}),
  52.     # Uncomment the admin/doc line below to enable admin documentation:
  53.     # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
  54.  
  55.     # Uncomment the next line to enable the admin:
  56.     url(r'^admin/', include(admin.site.urls)),
  57.     url("^admin-media/(?P<path>.*)$", "django.views.static.serve", {"document_root": fromRelativePath( "../design/static/admin-media")})
  58. )
  59.  
  60. add_catalog_product_url(urlpatterns)
  61. add_catalog_categories_url(urlpatterns)
  62. add_html_page_url(urlpatterns)