Hi Guys I am learning Django and trying to use Bootstrap, I already download bootstrap and put it under 'D:\django14\projects\nomina\nom_mex\static', I have Django 1.4 and use the developer server "runserver". According Django's documentation says referent it I need to use STATICFILES_DIRS and STATIC_URL parameters in my settings.py what else do I have to take in count to run bootstrap ?, It seems I have something wrong in my settings.py or may be in my urls.py, I left my project's files hoping somebody can help me, the template I am testing is the index.html.
I will appreciate any observations or suggestions... Thanks in advance. Jose Galvan -- 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 post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.{% extends "D:/django14/projects/nomina/nom_mex/templates/nom_mex/base.html" %} {% block content %}
Lista de empleados
{{ static_url }}-
{% if lista_empleados %}
{% for empleado in lista_empleados %}
- {{empleado.nombre}} {{empleado.ap_paterno}} {{empleado.ap_materno}} {% endfor%}
No hay empleados registrados !.
{% endif %} Crear empleado {% endblock %}# Create your views here. from django.shortcuts import render_to_response, get_object_or_404 from nom_mex.forms import EmpleadoForm from nom_mex.models import Empleado from django.template import RequestContext from django.http import HttpResponse def index(request): lista_empleados = Empleado.objects.all().order_by('ap_materno') return render_to_response('nom_mex/index.html',{'lista_empleados':lista_empleados}) def crea_empleado(request): if request.method=='POST': # if method is post then catch the info from the form, validate it and do commit form = EmpleadoForm(request.POST) if form.is_valid(): nombre=form.cleaned_data['nombre'] ap_paterno=form.cleaned_data['ap_paterno'] ap_materno=form.cleaned_data['ap_materno'] sexo=form.cleaned_data['sexo'] fecha_nacimiento=form.cleaned_data['fecha_nacimiento'] estatura=form.cleaned_data['estatura'] peso=form.cleaned_data['peso'] domicilio=form.cleaned_data['domicilio'] colonia=form.cleaned_data['colonia'] cod_postal=form.cleaned_data['cod_postal'] estado=form.cleaned_data['estado'] pais=form.cleaned_data['pais'] telefono_1=form.cleaned_data['telefono_1'] telefono_2=form.cleaned_data['telefono_2'] buzon_electronico=form.cleaned_data['buzon_electronico'] rfc=form.cleaned_data['rfc'] no_seg_social=form.cleaned_data['no_seg_social'] curp=form.cleaned_data['curp'] cartilla_militar=form.cleaned_data['cartilla_militar'] activo=form.cleaned_data['activo'] e=Empleado() e.nombre=nombre e.ap_paterno=ap_paterno e.ap_materno=ap_materno e.sexo=sexo e.fecha_nacimiento=fecha_nacimiento e.estatura=estatura e.peso=peso e.domicilio=domicilio e.colonia=colonia e.cod_postal=cod_postal e.estado=estado e.pais=pais e.telefono_1=telefono_1 e.telefono_2=telefono_2 e.buzon_electronico=buzon_electronico e.rfc=rfc e.no_seg_social=no_seg_social e.curp=curp e.cartilla_militar=cartilla_militar e.activo=activo e.save() # Commit to database mensaje='Registro Gravado correctamente' form=EmpleadoForm() lista_empleados = Empleado.objects.all().order_by('ap_materno') return render_to_response('nom_mex/index.html',{'lista_empleados':lista_empleados}) else: mensaje="Error en los datos de entrada caray, el registro no fue grabado" #form=EmpleadoForm() return render_to_response('nom_mex/crea_empleado.html',{'empleado_form':form,'mensaje':mensaje},context_instance=RequestContext(request)) else: form=EmpleadoForm() mensaje='Em metodo no fue post' return render_to_response('nom_mex/crea_empleado.html', {'empleado_form': form,'mensaje':mensaje},context_instance=RequestContext(request)) def edita_empleado(request, empleado_id): empleado = get_object_or_404(Empleado,pk=empleado_id) form = EmpleadoForm(request.POST or None,instance=empleado) if form.is_valid(): form.cleaned_data['nombre'] form.cleaned_data['ap_paterno'] form.cleaned_data['ap_materno'] form.cleaned_data['sexo'] form.cleaned_data['fecha_nacimiento'] form.cleaned_data['estatura'] form.cleaned_data['peso'] form.cleaned_data['domicilio'] form.cleaned_data['colonia'] form.cleaned_data['cod_postal'] form.cleaned_data['estado'] form.cleaned_data['pais'] form.cleaned_data['telefono_1'] form.cleaned_data['telefono_2'] form.cleaned_data['buzon_electronico'] form.cleaned_data['rfc'] form.cleaned_data['no_seg_social'] form.cleaned_data['curp'] form.cleaned_data['cartilla_militar'] form.cleaned_data['activo'] form.save() form=EmpleadoForm() lista_empleados = Empleado.objects.all().order_by('ap_materno') return render_to_response('nom_mex/index.html',{'lista_empleados':lista_empleados}) else: mensaje = 'Forma Invalida !entro a metodo get' return render_to_response('nom_mex/edita_empleado.html', {'empleado_form': form,'empleado':empleado,'mensaje':mensaje},context_instance=RequestContext(request))Title: {% block title %}Mi sitio padre{% endblock %}
{% block content %}{% endblock %}
# Django settings for nomina project. #import os DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Name', 'your_em...@example.com'), ) MANAGERS = ADMINS DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'nomina', # Or path to database file if using sqlite3. 'USER': 'root', # Not used with sqlite3. 'PASSWORD': 'malher', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } } # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all choices may be available on all operating systems. # On Unix systems, a value of None will cause Django to use the same # timezone as the operating system. # If running in a Windows environment this must be set to the same as your # system time zone. TIME_ZONE = 'America/Chicago' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'en-us' SITE_ID = 1 # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. USE_I18N = True # If you set this to False, Django will not format dates, numbers and # calendars according to the current locale. USE_L10N = True # If you set this to False, Django will not use timezone-aware datetimes. USE_TZ = True # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/home/media/media.lawrence.com/media/" #MEDIA_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__),'bootstrap')) MEDIA_ROOT = '' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" MEDIA_URL = '' # Absolute path to the directory static files should be collected to. # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. # Example: "/home/media/media.lawrence.com/static/" STATIC_ROOT = '' # URL prefix for static files. # Example: "http://media.lawrence.com/static/" #STATIC_URL = '/static/' STATIC_URL = '/static/' # Additional locations of static files STATICFILES_DIRS = ( # Put strings here, like "/home/html/static" or "C:/www/django/static". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. "d:/django14/projects/nomina/nom_mex/static", ) # List of finder classes that know how to find static files in # various locations. STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) # Make this unique, and don't share it with anybody. SECRET_KEY = 'tb*t1)7#h0+d1+k9&x^&xbw!nth6k%o*+y@v$wn-b)k)b^6ab$' # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', # 'django.template.loaders.eggs.Loader', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', # Uncomment the next line for simple clickjacking protection: # 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) ROOT_URLCONF = 'nomina.urls' # Python dotted path to the WSGI application used by Django's runserver. WSGI_APPLICATION = 'nomina.wsgi.application' TEMPLATE_DIRS = ( #'D:\django14\projects\nomina\templates\nom_mex' 'D:/django14/projects/nomina/nom_mex/templates' #'D:/django14/projects/nomina/templates' #'D:/django14/projects/nomina/templates/' # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. ) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'nom_mex', ) # A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to # the site admins on every HTTP 500 error when DEBUG=False. # See http://docs.djangoproject.com/en/dev/topics/logging for # more details on how to customize your logging configuration. LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' } }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, } }
from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.conf.urls import patterns, include, url import settings #Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Examples: # url(r'^$', 'nomina.views.home', name='home'), # url(r'^nomina/', include('nomina.foo.urls')), #url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'), url(r'^nom_mex/$', 'nom_mex.views.index'), url(r'^nom_mex/(?P<empleado_id>\d+)/$', 'nom_mex.views.edita_empleado'), url(r'^nom_mex/crea_empleado/$', 'nom_mex.views.crea_empleado'), #url(r'^bootstrap/(?P<path>.*)$','django.views.static.serve',{'document_root':settings.MEDIA_ROOT}), #url(r'^nomina/$', 'nom_mex.views.index'), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), ) urlpatterns += staticfiles_urlpatterns()
# Create your views here. from django.shortcuts import render_to_response, get_object_or_404 from nom_mex.forms import EmpleadoForm from nom_mex.models import Empleado from django.template import RequestContext from django.http import HttpResponse def index(request): lista_empleados = Empleado.objects.all().order_by('ap_materno') return render_to_response('nom_mex/index.html',{'lista_empleados':lista_empleados}) def crea_empleado(request): if request.method=='POST': # if method is post then catch the info from the form, validate it and do commit form = EmpleadoForm(request.POST) if form.is_valid(): nombre=form.cleaned_data['nombre'] ap_paterno=form.cleaned_data['ap_paterno'] ap_materno=form.cleaned_data['ap_materno'] sexo=form.cleaned_data['sexo'] fecha_nacimiento=form.cleaned_data['fecha_nacimiento'] estatura=form.cleaned_data['estatura'] peso=form.cleaned_data['peso'] domicilio=form.cleaned_data['domicilio'] colonia=form.cleaned_data['colonia'] cod_postal=form.cleaned_data['cod_postal'] estado=form.cleaned_data['estado'] pais=form.cleaned_data['pais'] telefono_1=form.cleaned_data['telefono_1'] telefono_2=form.cleaned_data['telefono_2'] buzon_electronico=form.cleaned_data['buzon_electronico'] rfc=form.cleaned_data['rfc'] no_seg_social=form.cleaned_data['no_seg_social'] curp=form.cleaned_data['curp'] cartilla_militar=form.cleaned_data['cartilla_militar'] activo=form.cleaned_data['activo'] e=Empleado() e.nombre=nombre e.ap_paterno=ap_paterno e.ap_materno=ap_materno e.sexo=sexo e.fecha_nacimiento=fecha_nacimiento e.estatura=estatura e.peso=peso e.domicilio=domicilio e.colonia=colonia e.cod_postal=cod_postal e.estado=estado e.pais=pais e.telefono_1=telefono_1 e.telefono_2=telefono_2 e.buzon_electronico=buzon_electronico e.rfc=rfc e.no_seg_social=no_seg_social e.curp=curp e.cartilla_militar=cartilla_militar e.activo=activo e.save() # Commit to database mensaje='Registro Gravado correctamente' form=EmpleadoForm() lista_empleados = Empleado.objects.all().order_by('ap_materno') return render_to_response('nom_mex/index.html',{'lista_empleados':lista_empleados}) else: mensaje="Error en los datos de entrada caray, el registro no fue grabado" #form=EmpleadoForm() return render_to_response('nom_mex/crea_empleado.html',{'empleado_form':form,'mensaje':mensaje},context_instance=RequestContext(request)) else: form=EmpleadoForm() mensaje='Em metodo no fue post' return render_to_response('nom_mex/crea_empleado.html', {'empleado_form': form,'mensaje':mensaje},context_instance=RequestContext(request)) def edita_empleado(request, empleado_id): empleado = get_object_or_404(Empleado,pk=empleado_id) form = EmpleadoForm(request.POST or None,instance=empleado) if form.is_valid(): form.cleaned_data['nombre'] form.cleaned_data['ap_paterno'] form.cleaned_data['ap_materno'] form.cleaned_data['sexo'] form.cleaned_data['fecha_nacimiento'] form.cleaned_data['estatura'] form.cleaned_data['peso'] form.cleaned_data['domicilio'] form.cleaned_data['colonia'] form.cleaned_data['cod_postal'] form.cleaned_data['estado'] form.cleaned_data['pais'] form.cleaned_data['telefono_1'] form.cleaned_data['telefono_2'] form.cleaned_data['buzon_electronico'] form.cleaned_data['rfc'] form.cleaned_data['no_seg_social'] form.cleaned_data['curp'] form.cleaned_data['cartilla_militar'] form.cleaned_data['activo'] form.save() form=EmpleadoForm() lista_empleados = Empleado.objects.all().order_by('ap_materno') return render_to_response('nom_mex/index.html',{'lista_empleados':lista_empleados}) else: mensaje = 'Forma Invalida !entro a metodo get' return render_to_response('nom_mex/edita_empleado.html', {'empleado_form': form,'empleado':empleado,'mensaje':mensaje},context_instance=RequestContext(request))