My model
`class Station(models.Model):
"""Station service."""
OPEN = 1
CLOSE = 0
STATUTLIST = (
(OPEN, _("Ouverte")),
(CLOSE, _("Fermée")),
)
nom_station = models.CharField(
_('Nom de la station'), max_length=30)
statut_station = models.CharField(
_('Ouverte ou fermée'),
max_length=1,
choices=STATUTLIST, default=OPEN)
city = models.ForeignKey(City, verbose_name=_('Ville'))
location = PlainLocationField(
based_fields=['city'], zoom=7)
photo_station = models.ImageField(
_("Photo"),
upload_to=utils.photo_file_path,
storage=utils.photo_storage,
null=True,
blank=True,
)
telephone = PhoneNumberField(_('Numero de téléphone'), null=True)`
My view
`def add_station_view(request, station_id=None):
"""Ajout et modification d'une station."""
template_name = "backend/main/add_station.html"
args = {}
args.update(csrf(request))
args['meta_keyword'] = args['home_title'] = _('Station')
args['meta_description'] = _('Création d\'une nouvelle station.')
if station_id is not None:
args['cobject'] = get_object_or_404(
sitemodels.Station, id=station_id)
args['meta_description'] = _(
'Editer %s' % (args['cobject'].get_nom_station()))
form = siteforms.StationForm(
request=request,
instance=args['cobject']
)
if request.method == 'POST':
if 'cobject' in args and form.has_changed():
form = siteforms.StationForm(
request.POST,
request=request,
instance=args['cobject'])
args['updated'] = True
else:
new_station = sitemodels.Station()
form = siteforms.StationForm(
request.POST,
request=request,
instance=new_station)
if form.is_valid():
obj = form.save(commit=False)
obj.save()
if 'updated' in args:
messages.success(request, STDUMSG)
else:
obj.cree_parking()
obj.cree_catalogue()
messages.success(
request, _('Nouvelle station ajoutée'))
if 'save_and_add_another' in request.POST:
return HttpResponseRedirect(
reverse(
'ppsmsite:addstation',
current_app=request.resolver_match.namespace,
)
)
return HttpResponseRedirect(
reverse(
'ppsmsite:liststatio',
current_app=request.resolver_match.namespace,
)
)
else:
if 'cobject' not in args:
form = siteforms.StationForm(request=request)
args['form'] = form
return render_to_response(
template_name,
args,
context_instance=RequestContext(request)
)`
My form:
`class StationForm(forms.ModelForm):
"""Docstring for StationsForm."""
def __init__(self, *args, **kwargs):
"""Form Init."""
self.request = kwargs.pop('request', None)
super(StationForm, self).__init__(*args, **kwargs)
class Meta:
"""Docstring for StationForm meta."""
model = sitemodels.Station
fields = [
'telephone',
'photo_station', 'location', 'city', 'nom_station']`
When i exclude field in form my view work, but when i try to render it with location field it show me this error:
TemplateDoesNotExist at /station/ajouter/
backend/main/add_station.html
Request Method: GET
Request URL: http://localhost:8000/station/ajouter/
Django Version: 1.8.7
Exception Type: TemplateDoesNotExist
Exception Value:
backend/main/add_station.html
Exception Location: C:\Python34\lib\site-packages\django\template\loader.py in render_to_string, line 137
Python Executable: C:\Python34\python.exe
Python Version: 3.4.4
Python Path:
['C:\Users\CRESUS\Documents\projet\ppsm',
'C:\Python34\lib\site-packages\django_datetime_widget-0.9.3-py3.4.egg',
'C:\WINDOWS\SYSTEM32\python34.zip',
'C:\Python34\DLLs',
'C:\Python34\lib',
'C:\Python34',
'C:\Python34\lib\site-packages']
Server time: jeu, 7 Avr 2016 02:28:29 +0100
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
C:\Users\CRESUS\Documents\projet\ppsm\templates\backend\main\add_station.html (File exists)
Using loader django.template.loaders.app_directories.Loader:
C:\Python34\lib\site-packages\suit\templates\backend\main\add_station.html (File does not exist)
C:\Python34\lib\site-packages\django\contrib\admin\templates\backend\main\add_station.html (File does not exist)
C:\Python34\lib\site-packages\django\contrib\auth\templates\backend\main\add_station.html (File does not exist)
C:\Python34\lib\site-packages\django\contrib\gis\templates\backend\main\add_station.html (File does not exist)
C:\Python34\lib\site-packages\ckeditor\templates\backend\main\add_station.html (File does not exist)
C:\Python34\lib\site-packages\ckeditor_uploader\templates\backend\main\add_station.html (File does not exist)
C:\Python34\lib\site-packages\leaflet\templates\backend\main\add_station.html (File does not exist)
C:\Python34\lib\site-packages\geoposition\templates\backend\main\add_station.html (File does not exist)
Please help if i forget to do something