Re: images
On Feb 15, 10:16 am, Praveen Krishna R wrote: > *plz Check django official docs to find out how static files are served on > production and development server.* > * > * > *in the dev server include a similiar snippet into your projects > urls.py, urlpatterns:* > * > * > *(r'^site_media/(?P.*)$', > 'django.views.static.serve',{'document_root': > 'D:/djangoprojects/praveensprofile/templates/static'}),* > * > * > ***and in the templates something similar to the below text.* > * > * > * > * > * > * > On Tue, Feb 15, 2011 at 1:07 PM, Szabo, Patrick (LNG-VIE) < > > > > patrick.sz...@lexisnexis.at> wrote: > > How do i check the logs !? > > I'm using the integrated webserver. > > > Kind regards > > > . . . . . . . . . . . . . . . . . . . . . . . . . . > > Patrick Szabo > > XSLT-Entwickler > > LexisNexis > > Marxergasse 25, 1030 Wien > > > mailto:patrick.sz...@lexisnexis.at > > Tel.: +43 (1) 534 52 - 1573 > > Fax: +43 (1) 534 52 - 146 > > > -Ursprüngliche Nachricht- > > > Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] > > Im Auftrag von Kenneth Gonsalves > > Gesendet: Dienstag, 15. Februar 2011 11:05 > > An: django-users@googlegroups.com > > Betreff: Re: images > > > On Tue, 2011-02-15 at 11:00 +0100, Szabo, Patrick (LNG-VIE) wrote: > > > Unfortunately i only get the "alt text" shown and not the image. > > > The image is in the same directory as the template. > > > check your logs to see where it is searching for your image > > -- > > regards > > KG > >http://lawgon.livejournal.com > > Coimbatore LUG rox > >http://ilugcbe.techstud.org/ > > > -- > > 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. > > > -- > > 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. > > -- > Thanks and Regards, > *Praveen Krishna R* Just to slightly expand on what Praveen said. Static files are served differently from templates. Templates are loaded from views using a configured template path. Static files are served by your web server according to its configuration. If you are using the development web server then you need to configure Django as Praveen suggests to set the media path. if you are serving any other static content then you have already done this. As and when you move to a production web server, you will need to configure that appropriately. You should be able to leave the links unchanged (unless you do something daft) and just configure the web server correctly. Cheers, Ian -- 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.
Re: how to use render_to_response, ajax and javascript variables
Sorry, other posters have picked up two of my errors. It is a while since I used application/json and I was running on (incorrect) memory. My reasoning for using plain text is as follows. I regard parsing JSON using eval() as a security risk on the client side. If you have complete control of the server side then it is safe but I choose to be conservative and safer. I use the json2.js library to parse JSON rather than using eval() and making the MIME type text prevents accidental use of eval. Here are some links about parsing JSON. http://funkatron.com/site/comments/safely-parsing-json-in-javascript/ http://yuiblog.com/blog/2007/04/10/json-and-browser-security/ With regard to marking fields as safe - yes, Matt Hoskins is right. I have fixed that in a later version of my template but I didn't have the latest version to hand (different laptop) so I used an old version. In some cases, I don't use templates to build a JSON response. It can be straightforward to write it as a string inline. I don't personally yet use the built in Python JSON module as I don't want to limit the Python versions that I can deploy with but I am sure that I will move to this at some point. Cheers Ian On Jun 17, 9:37 am, Matt Hoskins wrote: > I was just copying Ian's choice of mimetype - see Ian's comment above > "I choose text/plain deliberately but you might choose text/json (or > something else)."... Although it's worth pointing out that "text/json" > shouldn't be used, since "application/json" is, as you rightly point, > the mimetype for json data :). > > On Jun 17, 9:18 am, Dmitry Dulepov wrote: > > > > > Small correction: mime type should be application/json. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Re: how to use render_to_response, ajax and javascript variables
Hi Alex, here is a small example of a JSON response. I don't mix HTML and JSON personally (I use HTML pages and then fetch JSON via AJAX calls so). Here is a fragment of code from one of my views: t = loader.get_template('members/member_info.json') c = Context({'member_set':member_set}) return HttpResponse(t.render(c), mimetype="text/plain") Here is the template: {"results":[ {% for one_member in member_set %} { "id":"{{one_member.id}}", "username":"{{one_member.username}}", "first_name":"{{one_member.first_name}}", "last_name":"{{one_member.last_name}}" }, {% endfor %} ]} I choose text/plain deliberately but you might choose text/json (or something else). if you embed HTML in JSON then you will need to be careful that the HTML does not itself contain characters that break the JSON (e.g. quotation marks). Cheers Ian On Jun 16, 8:46 pm, Alex wrote: > Thanks all. I may go with Matt's idea of serialising html + other data > to json and decoding client side. I'm not totally keen though because > this abandons a very nice rollup of functionality in django's > render_to_response (I am not familiar with how to write the template > as JSON and rendering to that. Keeping the template as html seems like > the right thing to do). I was hoping you'd scream 'don't be daft - > everyone does this...' :) > > Alex -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Re: Multiple AJAX sends within a views.py-function
Cool. That is a clever way to subvert (I don't mean this negatively) the response generation. I do have a couple of comments: 1) It relies on the response being sent to the client as it is generated and not buffered by the server. That is clearly working for you and I don't know the internals of the different web servers to know if any would break this. I suspect this will work with all servers so nice trick. 2) I would be worried by resources on the web server if you expect many connections of this type. In most servers that I have seen, each request is assigned to a thread from a pool and the thread is not freed up until the request is completed. Each of these requests will tie up a thread until it is completed (I think). This is likely to work well for a small number of simultaneous connections but if you had more simultaneous clients than threads in your pool, I would expect new requests to be blocked / delayed. If you only expect one or a small number of clients to use this request at one time then you are fine. If you want to scale this then I think that you may have a problem. I suggest testing this by setting up more simultaneous clients than your server has threads set in the pool. The test might be fiddly to set up and you could reconfigure the server to have fewer threads and add delays into the calculations to make it easier to test. This is the reason why I chose to build my own custom server for long- running requests but that causes a lot of extra work and possible bugs so I don't recommend it if there is any alternative. Cheers Ian On Jun 15, 8:45 pm, Christoph Siedentop wrote: > Hi Dmitry, hi Ian, > > thanks for the help. > > I got it to work. Here is what I am doing. > > Django gets a request for "/data.json". A view function is called. > This is my function: > > def data(request): > return HttpResponse(subsampling(), mimetype='application/javascript') > > subsampling() is an iterator, i.e. it yields data every once in while. > Look > at:http://docs.djangoproject.com/en/dev/ref/request-response/#passing-it... > > I am yielding simplejson.dumps(my_dict) + '\n' which is then received > by the client. The original request for data.json came from an ajax > function (using jQuery). At the beginning using 'beforeSend' I start a > function that takes the XmlHttpRequest.responseText and sees how much > data has arrived and appends that data to the already existing data. I > do this every 10ms and stop once the xmr.readyState indicates that the > connection was closed. > > I am quite satisfied with this result. It does not use much memory and > is much faster (and feels much faster) than before. > > I tested it under Chromium, Firefox and Konqueror. I will add some > additional functionality and make it a nice graphics module in the > late summer. Probably GPL'ed. It would be for people like me, who have > lots of data and want to make them available interactively. > > Regards, > Christoph > <> -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Re: how to use render_to_response, ajax and javascript variables
Just one comment - Django lets you render to JSON just as easily as rendering to HTML (or XML). You just write your template as JSON and set the MIME type for the response accordingly. Because I control my JSON parsing on the client side, I set the MIME type to text/plain but you could set to another if you wanted. I realise that this doesn't actually solve your problem of combining HTML and JSON in a response and I think one of the other comments addresses this but I wanted to make the point that JSON by itself is easy. Cheers Ian On Jun 16, 1:17 pm, Alex wrote: > Hi, > > Please can anyone help with an app architecture problem I am having? > (I am quite new to Django) > > I have an app which which serves up XHR requests (via YUI3 io > uitility) to urlpatterns. The views make HttpResponses using > render_to_response like so: > > return render_to_response("registration/register.html", { > 'form': form, > }, context_instance=RequestContext(request)) > > That is all fine: The html content is rendered in the relevant div > (using a YUI3 io's success callback) . > > But the problem I have - and I may be thinking about this in the wrong > way - is that I also want to pick out some variables from the response > to use in my js success callback. If I wasn't using django templating > this could be straightforwardly achieved with a JSON response parsed > client side. So my difficulty is that I want both a rendered template > response and some JSON response in the same callback... I have thought > about 'enriching' the render_to_response context with these additional > variables, inserting them in hidden html fields and then querying the > dom for their values - but that feels awkward and also means the > response has to be added to the dom before the js can act on their > values. > > This seems like a familiar nut that must be well documented > somewhere... :) any help, pointers very appreciated. > > Thanks > Alex -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Re: Django architecture question
I have a site that has quite a few Django based pages plus login etc. and I certainly had to structure the code over multiple modules. I suggest that you do both a top-down and a bottom-up design (actually, iterate between these). Start with a top-down view which is the urls - list those and plan for a single view method for each url. I then started with a single view.py source file and added each view method to it. After a while. this single views.py grew too large to be easily manageable so I split it. There are two ways to split it. Firstly, having one file called views.py is only a convention. it is a useful convention but it can be broken so for one of my apps, I split the view methods into four separate source files and referred to those from urls.py. In my case, I had messages.py, groups.py etc. Secondly, as one of the other posters said, if you have commonly used utility functions then they can be pulled out into separate modules. Once you realise that the views.py is only a convention then it just becomes a question of structuring a large Python app. Hope this helps, Ian McDowall On Jun 15, 5:55 am, Joel Klabo wrote: > I am working on a simple site right now and the views are pretty easy. > Usually just iterate a loop of objects. But, I am trying to figure out > how a website with all different kinds of data, including a sign in > form, is setup in django. Is that all in one big view? Or, is there > some way to combine them? > > Any insight would be helpful, thank you. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Re: Multiple AJAX sends within a views.py-function
As the other posters say, this is not possible with standard HTTP and certainly not with Django. By default, HTTP is one request / one response and Django (and other web frameworks) are built on that. Take a look at the HTTP spec and try looking at the packet contents for HTTP requests - it is quite educational. Paying attention to the innards of HTTP, it is possible to have a response that is delivered in more than one packet and so the client can receive part of the response followed by more of the response later and so on. I think that this is normally used as a technique for long-polling and I am doubtful that the browser client will handle it as you want and even more doubtful that a Django (or similar) framework will handle it as you want. If you want to experiment with HTTP and server internals then it could be quite interesting but as a way to actually get the job done it is likely to be a red herring. Other techniques beyond straight HTTP include web sockets and server events - both part of HTML5. These would let your client receive updates from the server as and when ready. Unfortunately, these are not well supported by current browsers (AFAIK Chrome supports we sockets and Opera has a version of server sent events) and you will need a custom server. I am using similar techniques to implement real time event handling but I have had to build my own server and accept that I cannot use certain browsers. To go back to your original question and assuming that you want a simple way of getting the job done then I think that you either have to accept the delay and do the calculation in one go or handle multiple requests. Performing the calculation in one go may take some time but AJAX is asynchronous so the user can see what ever progress info you want to show (i.e. an hourglass). If the work really will take too long then multiple requests looks necessary but remember that you will need to cache the calculation between requests or do it in a separate thread and make it available. Remember that each Django request is normally run in isolation and nothing is persisted when it is finished unless you write it to a database. if you can make the calculation such that nothing needs to persist (or each request includes the result from the previous one) then that may be OK. Is there any option to pre-calculate so the results are easily availabl? Regards, Ian McDowall On Jun 11, 4:15 pm, Christoph wrote: > Hi, > > normally in views.py I have a function that takes a request and > returns a render_to_response or the like. I, however, would like it to > take a request and have Django reply with multiple responses. Is there > a way to do this, or is this not possible with HTTP anyway? > > What I am trying to achieve: Have a a view that gets called and in it > I have a JS/AJAX script that asks for some data. However, calculating > the data takes a while and it comes one after the other. So I thought > that I could send the data as soon as it becomes available. > > In my example I have a graph (using flot) and it would also look > natural to have the data points show up one by one. > > A different approach: Have JS ask for more data (using GET) until the > view responses sets a flag (NO_MORE_DATA = True). I don't like this, > since for me this looks like it defies the A in AJAX and the view > would lose all parameters (I.e. which points it already sent and which > not). However, I don't know much JS, nor AJAX nor do I understand the > HTTP protocol good enough. > > Maybe this has been done before? Is there a way of having server-side > generated AJAX-actions? Is there a way of having Django send something > within a views-function (as opposed to returning it at the end)? > > Some possible code: > > def my_view(request): > data = > MyModel.objects.filter('something').order_by('somethingelse') > for item in list(data): # Note, I don't do this but this is just > to show how what I want > send_json(do_something(item)) # send_json() is the crucial > (non-existing) function that I am looking for > return None # or maybe return Done or something like it > > Best regards, > Christoph -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Re: Creating sample users for testing
I had the same issue but I also wanted to create additional data for each user. It was straightforward to create a script to add users. I needed to import some bits to set up the Django environment and then I was able to create users with standard Django calls. Here is extracts from my code (with my custom tables omitted). This also include setting of the raw password (Django will hash it for you). The code could probably be made more elegant but it works. # Setup Django environment import settings # Assumed to be in the same directory. from django.core.management import setup_environ setup_environ(settings) from django.contrib.auth.models import User import django.contrib.auth def create_user( username, first_name, last_name, email, raw_password): new_user = User(username=username, first_name=first_name,\ last_name=last_name, email=email) new_user.set_password(raw_password) new_user.save() member_set = [\ ['biggles', 'Biggie', 'Bigglesworth', 'bigg...@raf.org'],\ ['algie', 'Algernon', 'Sidekick', 'al...@raf.org'],\ ['grumpy', 'Grumpy', 'Dwarf', 'gru...@7dwfs.com'],\ ['sleepy', 'Sleepy', 'Dwarf', 'sle...@7dwfs.com'],\ ['dopey', 'Dopey', 'Dwarf', 'do...@7dwfs.com'],\ ['doc', 'Doc', 'Dwarf', 'd...@7dwfs.com'],\ ] for one in member_set: create_user( one[0], one[1], one[2], one[3], one[0]) On Mar 22, 12:26 pm, Ivan Uemlianin wrote: > Dear All > > I'd like to create a bunch of sample users for testing a django > website. I was going down the road of using an initial_data fixture, > but there seem to be a couple of problems with this: > > - Can I supply partial data in initial_data, i.e. only auth.user info > (at the moment, username and password, and it seems to require last > login)? When I do this, syncdb persists in asking me for an admin > user (even when the previously given admin user still works). > > - How should I specify the password field in the fixture? dumpdata > outputs a hash. Do I need to write some script to generate hashes > from given passwords? > > I'm now thinking a fixture might not be the right way to go: it might > be better to have a little script to add users once syncdb is done. > As well as allowing me to provide plain text passwords, I could easily > add site-specific attributes when I need them (dave.favourite_colour = > 'orange'; bob.online = True, etc). > > Is that second method just reinventing the fixture, or is it more > appropriate here? > > Thanks and best wishes > > Ivan -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Re: OT: Drawing lines in the browser
On Aug 18, 8:53 am, Thomas Guettler wrote: > Hi, > > this is offtopic: How can you draw lines in a (django) web application? > > I think you need to use flash or java to do it. I googled for it, but found > only beta > quality projects. > > Has anyone experience with this? > > Thomas > > -- > Thomas Guettler,http://www.thomas-guettler.de/ > E-Mail: guettli (*) thomas-guettler + de Depends on what type of line. It is technically possible to use SVG. You can embed an SVG image in HTML and then draw lines (or circles etc.) in it. The SVG is just XMl and Django's templating works fine for that. There are some technical catches about the type of the document and namespaces but I can provide a worked example. The drawback is that not all browsers support SVG well. This appears to work well in recent versions of Firefox but not well in IE. Ian McDowall --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---