The problem you are seeing regarding the link i mentioned briefly in my last post. Django does auto escapingbe default of all template vars and values. In your case that means that you see the html you wrote because the <>" has been converted to a code that will display the signs but disable the code. You can either use the |safe tag or stop the auto escaping entirely for a part or the whole template. But you need to be careful if you have user inputs on your site.
If you plan on using your global functions in the template only you should considder creating your own template tags. That would also solve any import problems. You can read about both things in the django docs, can't give you the links right now as I'm on mobile but search for template tags or auto escape and you should hit some relevant stuff. ~Briel On 9 Mar., 19:12, Julián C. Pérez <jcp...@gmail.com> wrote: > ok briel, maybe i should explain myself better > you're right about the function with that innecesary 'request' > object... but i'd need it for any other function -yet to be > implemented > -by the way, i use the shortcut render_to_response > > regarding the html stuff, with the function defined early if i make > the call as: > - in a html template... > <body> > ... > {{ ocultarEstado }} > .. > </body> > i get: <a class="a_linkPequeno" href="#" onClick="cerrarBloque(this)"> > (aceptar)</a> > instead of a link: (aceptar) > > regarding the part of importing the functions... > what i want is to import all the functions within that > 'globalValues.py' > actually i have only the import for the ocultarEstado method, done in > the settings.py file with: > ... > TEMPLATE_CONTEXT_PROCESSORS = ( ... > 'myproject.globalValues.ocultarEstado', ... ) > ... > i mean, i don't want to import each new method like: > ... > TEMPLATE_CONTEXT_PROCESSORS = ( ... > 'myproject.globalValues.function1', > 'myproject.globalValues.function2', > 'myproject.globalValues.function3', ... ) > ... > but something like: 'myproject.globalValues.*' > > On 9 mar, 11:35, Briel <toppe...@gmail.com> wrote: > > > Hi and welcome to django. > > > In regards to question 1, it looks like you are missing something. The > > request object, that you have as parameter in your function, is used > > in the views.py file. The object has a lot of the info that you need, > > like the user, the post data if any ect. If you want to make a > > functions like the one above, you dont need the request object in it, > > as you dont use it in the function and isn't required. > > I'm not sure what you mean with getting the output as html. Once you > > get it to a template, it wont matter how it got generated, as long as > > you dont escape the html chars. > > > If you want to import fx all functions in a fille, you can do it in > > different ways. > > You could do: > > from myproject.globalValues import * > > This would give you the functions like the ocultarEstado in the global > > namespace, so you could call it by typing ocultarEstado(...). Another > > way to import would be to do, > > from myproject import globalValues as global > > this would give you all the functions in the globalValues file on > > "global", so you could do, global.ocultarEstado(...). You could change > > the name after "as" into anything you like. > > > ~Briel > > > On 9 Mar., 17:11, Julián C. Pérez <jcp...@gmail.com> wrote: > > > > hi everyone from colimbia > > > i'm new on django... so far, i love it... i'm very used to php, but > > > the solution with django/python is just awesome > > > i have started a project and i've been catching up with the basics... > > > right now i have 2 doubts... > > > > 1. i created a file called 'globalValues.py' in the root folder of my > > > project... the purpose?? to put in there all python functions created > > > by me and called frequently among the code, and also to put some html > > > 'shortcuts' to common stuff... > > > the code in that file so far is next: > > > # ---------- > > > # start code globalValues.py > > > def ocultarEstado(request): > > > return { 'ocultarEstado' : '<p>hi u user!</p>' } > > > # end code > > > # ---------- > > > very short right now jeje > > > my question about it: how can i make 'ocultarEstado' function to > > > output the string as html, instead of its raw representation?? > > > > 2. said all above, in my 'settings.py' file there is the import as it > > > follows: > > > # ---------- > > > TEMPLATE_CONTEXT_PROCESSORS = ( > > > 'django.core.context_processors.auth', > > > 'django.core.context_processors.debug', > > > 'django.core.context_processors.i18n', > > > 'django.core.context_processors.media', > > > 'myproject.globalValues.ocultarEstado', > > > ) > > > # ---------- > > > my question here: how can i import all functions inside 'globalValues' > > > file with one call?? -i'm looking for a "myproject.globalValues.*" > > > kind of expression"- making every function calling with an entry is > > > quite large... > > > > thank u all! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---