Re: Django + ajax waiting page, can not redirect to result page
awrence.com/media/" 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/' # URL prefix for admin static files -- CSS, JavaScript and images. # Make sure to use a trailing slash. # Examples: "http://foo.com/static/admin/";, "/static/admin/". ADMIN_MEDIA_PREFIX = '/static/admin/' # 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. ) # 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 = 'mpizo)=nw5%bzy3@pp_)^%o1&+)_=$m^ai0wqtse&=e06b5=0z' # 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', ) ROOT_URLCONF = 'mytest.urls' TEMPLATE_DIRS = ( 'C:/Users/yun/tmp/mytest/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', ) # 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. # 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, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler' } }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, } } -- 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: Django + ajax waiting page, can not redirect to result page
I will try it 在 2011年12月16日 上午12:25,Denis Darii 写道: > You can view your js errors by pressing CTRL+SWIFT+J in Firefox but i > highly recommend you to install Firebug addon which allow you to view also > the received data from your ajax request. > > > On Fri, Dec 16, 2011 at 5:24 AM, yun li wrote: > >> Since I am really know nothing about ajax, I am not sure if I >> understand "try changing the return value from the view to a string " >> the right way. I changed the definition of run_DHM this way >> >> def run_DHM(request): >>xx = {'ok':true} >>return(xx) >> >> but still the same as before. >> >> and how I can check if there is any error in JavaScript console in my >> browser ? >> >> >> On 12月15日, 上午8时57分, Brett Epps wrote: >> > I think the problem might be that you're using the getJSON function, >> which >> > expects a JSON response, but your view returns 'OK', which is not valid >> > JSON. The callback you have given to getJSON only gets called on >> "success" >> > (meaning a JSON document was retrieved) - that's why nothing is >> happening >> > for you right now. Try changing the return value from the view to a >> string >> > containing: >> > >> > {"ok": true} >> > >> > And then change this line in the JavaScript: >> > >> > if (data == 'OK') { >> > >> > to: >> > >> > if (data.ok) { >> > >> > I think it should work with those changes. If it doesn't, try checking >> the >> > JavaScript console in your browser for any errors. >> > >> > Brett >> > >> > On 12/14/11 4:03 PM, "yun li" wrote: >> > >> > >> > >> > >> > >> > >> > >> > >But it still cannot work. when I submit something, it goes to the >> > >please_wait page showing "please wait" and then nothing happened. I >> > >really have no knowledge on ajax, so is there something I need to >> > >install or import in my projects? and how can I test if codes in >> > > ... really invoked? >> > >> > >Thanks, >> > >> > >On 12月14日, 下午1时47分, Brett Epps wrote: >> > >> I think the problem is that your tag is incorrect. You're >> using >> > >> the same one to load jQuery and to add your code, so your JavaScript >> is >> > >> not getting run. The file "please_wait.html" should look like this: >> > >> > >> <!DOCTYPE html> >> > >> <html> >> > >> <head> >> > >> <title>Please wait.</title> >> > >> <meta charset="utf-8"> >> > >> <script >> > >>src="<a rel="nofollow" href="http://code.jquery.com/jquery-1.7.1.min.js"">http://code.jquery.com/jquery-1.7.1.min.js"</a>;> >> > >> >> > >> $(function() { >> > >> $.getJSON('{% url run_DHM %}', function(data) { >> > >> if (data == 'OK') { >> > >> window.location.href = '{% url displayDHM >> %}'; >> > >> } else { >> > >> alert(data); >> > >> } >> > >> }); >> > >> }); >> > >> >> > >> >> > >> >> > >> Please wait. >> > >> >> > >> >> > >> > >> I've also added a bit more to the HTML file so that it is more >> > >> standards-compliant. >> > >> > >> Brett >> > >> > >> On 12/14/11 1:23 PM, "yun li" wrote: >> > >> > >> >Hi, >> > >> >Does anyone can help? >> > >> >Here are all contents in my files, I tried variable ways, but when I >> > >> >submit a form, it only return the please_wait page and then stay >> there >> > >> >forever. There is no redirect happened. >> > >> >Since I want to check if it works first, there is no actual >> > >> >calculation in the code. >> > >> > &g
Re: Django + ajax waiting page, can not redirect to result page
Since I am really know nothing about ajax, I am not sure if I understand "try changing the return value from the view to a string " the right way. I changed the definition of run_DHM this way def run_DHM(request): xx = {'ok':true} return(xx) but still the same as before. and how I can check if there is any error in JavaScript console in my browser ? On 12月15日, 上午8时57分, Brett Epps wrote: > I think the problem might be that you're using the getJSON function, which > expects a JSON response, but your view returns 'OK', which is not valid > JSON. The callback you have given to getJSON only gets called on "success" > (meaning a JSON document was retrieved) - that's why nothing is happening > for you right now. Try changing the return value from the view to a string > containing: > > {"ok": true} > > And then change this line in the JavaScript: > > if (data == 'OK') { > > to: > > if (data.ok) { > > I think it should work with those changes. If it doesn't, try checking the > JavaScript console in your browser for any errors. > > Brett > > On 12/14/11 4:03 PM, "yun li" wrote: > > > > > > > > >But it still cannot work. when I submit something, it goes to the > >please_wait page showing "please wait" and then nothing happened. I > >really have no knowledge on ajax, so is there something I need to > >install or import in my projects? and how can I test if codes in > > ... really invoked? > > >Thanks, > > >On 12月14日, 下午1时47分, Brett Epps wrote: > >> I think the problem is that your tag is incorrect. You're using > >> the same one to load jQuery and to add your code, so your JavaScript is > >> not getting run. The file "please_wait.html" should look like this: > > >> <!DOCTYPE html> > >> <html> > >> <head> > >> <title>Please wait.</title> > >> <meta charset="utf-8"> > >> <script > >>src="<a rel="nofollow" href="http://code.jquery.com/jquery-1.7.1.min.js"">http://code.jquery.com/jquery-1.7.1.min.js"</a>;> > >> > >> $(function() { > >> $.getJSON('{% url run_DHM %}', function(data) { > >> if (data == 'OK') { > >> window.location.href = '{% url displayDHM %}'; > >> } else { > >> alert(data); > >> } > >> }); > >> }); > >> > >> > >> > >> Please wait. > >> > >> > > >> I've also added a bit more to the HTML file so that it is more > >> standards-compliant. > > >> Brett > > >> On 12/14/11 1:23 PM, "yun li" wrote: > > >> >Hi, > >> >Does anyone can help? > >> >Here are all contents in my files, I tried variable ways, but when I > >> >submit a form, it only return the please_wait page and then stay there > >> >forever. There is no redirect happened. > >> >Since I want to check if it works first, there is no actual > >> >calculation in the code. > > >> ># url.py > >> >urlpatterns = patterns('', > >> >(r'^test$',views.test_form), > >> >(r'^please_wait', views.please_wait), > >> >url(r'^run_DHM$', views.run_DHM, name="run_DHM") , > >> >url(r'^displayDHM', views.display_DHM, name="displayDHM") > >> >) > > >> >### view.py # > >> >def test_form(request): > >> >return render_to_response('test.html') > > >> >def please_wait(request): > >> >return render_to_response('please_wait.html') > > >> >def run_DHM(request): > >> > ### lengthy calculations... ... > >> >return HttpResponse("OK") > > >> >def display_DHM(request): > >> >return render_to_response('display_DHM.html') > > >> >## test.html ### > >> >{% extends "baseFrame.html" %} > > >> >{% block maincontent %} > >> > > >> > Test: > >> > > >> > Type
Re: Django + ajax waiting page, can not redirect to result page
But it still cannot work. when I submit something, it goes to the please_wait page showing "please wait" and then nothing happened. I really have no knowledge on ajax, so is there something I need to install or import in my projects? and how can I test if codes in ... really invoked? Thanks, On 12月14日, 下午1时47分, Brett Epps wrote: > I think the problem is that your tag is incorrect. You're using > the same one to load jQuery and to add your code, so your JavaScript is > not getting run. The file "please_wait.html" should look like this: > > <!DOCTYPE html> > <html> > <head> > <title>Please wait.</title> > <meta charset="utf-8"> > <script src="<a rel="nofollow" href="http://code.jquery.com/jquery-1.7.1.min.js"">http://code.jquery.com/jquery-1.7.1.min.js"</a>;> > > $(function() { > $.getJSON('{% url run_DHM %}', function(data) { > if (data == 'OK') { > window.location.href = '{% url displayDHM %}'; > } else { > alert(data); > } > }); > }); > > > > Please wait. > > > > I've also added a bit more to the HTML file so that it is more > standards-compliant. > > Brett > > On 12/14/11 1:23 PM, "yun li" wrote: > > > > > > > > >Hi, > >Does anyone can help? > >Here are all contents in my files, I tried variable ways, but when I > >submit a form, it only return the please_wait page and then stay there > >forever. There is no redirect happened. > >Since I want to check if it works first, there is no actual > >calculation in the code. > > ># url.py > >urlpatterns = patterns('', > >(r'^test$',views.test_form), > >(r'^please_wait', views.please_wait), > >url(r'^run_DHM$', views.run_DHM, name="run_DHM") , > >url(r'^displayDHM', views.display_DHM, name="displayDHM") > >) > > >### view.py # > >def test_form(request): > >return render_to_response('test.html') > > >def please_wait(request): > >return render_to_response('please_wait.html') > > >def run_DHM(request): > > ### lengthy calculations... ... > >return HttpResponse("OK") > > >def display_DHM(request): > >return render_to_response('display_DHM.html') > > >## test.html ### > >{% extends "baseFrame.html" %} > > >{% block maincontent %} > > > > Test: > > > > Type your value in here: > >>textarea> > > > > > >{% endblock %} > > >### please_wait.html ## > > >Please wait > >http://code.jquery.com/</a> > >jquery-1.7.1.min.js"> > >$.getJSON('{% url run_DHM %}', function(data) { > >if (data == 'OK') { > > window.location.href = '{% url displayDHM %}'; > >} else { > > alert(data); > >} > >}); > > > > > > >### display_DHM.html # > > > >END FINALLY! > > > > >-- > >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.
Re: Django + ajax waiting page, can not redirect to result page
Hi, Does anyone can help? Here are all contents in my files, I tried variable ways, but when I submit a form, it only return the please_wait page and then stay there forever. There is no redirect happened. Since I want to check if it works first, there is no actual calculation in the code. # url.py urlpatterns = patterns('', (r'^test$',views.test_form), (r'^please_wait', views.please_wait), url(r'^run_DHM$', views.run_DHM, name="run_DHM") , url(r'^displayDHM', views.display_DHM, name="displayDHM") ) ### view.py # def test_form(request): return render_to_response('test.html') def please_wait(request): return render_to_response('please_wait.html') def run_DHM(request): ### lengthy calculations... ... return HttpResponse("OK") def display_DHM(request): return render_to_response('display_DHM.html') ## test.html ### {% extends "baseFrame.html" %} {% block maincontent %} Test: Type your value in here: {% endblock %} ### please_wait.html ## Please wait http://code.jquery.com/ jquery-1.7.1.min.js"> $.getJSON('{% url run_DHM %}', function(data) { if (data == 'OK') { window.location.href = '{% url displayDHM %}'; } else { alert(data); } }); ### display_DHM.html # END FINALLY! -- 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.
Django + ajax waiting page, can not redirect to result page
Hi all, I have the problem for constructing waiting page using Django + ajax. I followed instructions mentioned in the following link, http://groups.google.com/group/django-users/browse_thread/thread/c1b0d916bbf86868. However, when I run my program, it stops in http://127.0.0.1:8000/please_wait and will not redirect to the result page like "http://127.0.0.1:8000/ display_DHM" does anybody know what is going on? I basically use the following instructions. >>> >>> > # please_wait.html >>> >>> > ... >>> >>> > >> >>> > src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js";> >>> >>> > >>> >>> > $.get('{% url run_DHM %}', function(data) { >>> >>> > if (data == 'OK') { >>> >>> > window.location.href = '{% url display_DHM %}'; >>> >>> > } else { >>> >>> > alert(data); >>> >>> > } >>> >>> > }); >>> >>> > >>> >>> > Note I've used the shorthand urls above, you could just use >>> >>> > '/run_DHM/' >>> >>> > and >>> >>> > '/display_DHM/' instead of the url template tags. You could also use >>> >>> > the >>> >>> > full package path. Also note that the callback function I refer to >>> >>> > is >>> >>> > defined inline - the function(data) ... part. >>> >>> > # views.py >>> >>> > from django.http import HttpResponse >>> >>> > def please_wait(request): >>> >>> > return render_to_response('please_wait.html', ...) >>> >>> > def run_DHM(request): >>> >>> > # Do calculations, store results in request.session >>> >>> > ... >>> >>> > # If everything ok, return OK (otherwise return some error) >>> >>> > return HttpResponse('OK') >>> >>> > def display_DHM(request): >>> >>> > # Get results from session >>> >>> > return render_to_response('ran_DHM.html', ...) Thanks, trace -- 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.
There has a login user problem
Model: class X(models.Model): user = models.ForeignKey(User, blank=True, null=True) x= other() # I want to add current user when add X Form: class xForm(forms.ModelForm): class Meta: model = X exclude = ('marker') View: def add_X(request): print request.user#user has the logined user if request.method == 'POST': print request.user#user is None form = XForm(request) if form.is_valid(): x = form.save(commit=False) x.user = request.user x.save() return HttpResponseRedirect('/x/lists/') else: return render_to_response('x/x_form.html', {'form':xForm ()}) else: return render_to_response('x/x_form.html', {'form':xForm()}) give me a way --~--~-~--~~~---~--~~ 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: Inheritance through a ForeignKey field
Suppose that you have a Section model that has a foreign key to Magazine, and the field in the Section model is called magazine. You can then do something like this once you get the section: s = Section.objects.select_related.get() s.magazine.id will return the id of the magazine, if it has a name then s.magazine.name will return the name. This will do the all the related querries in one shot. You can also do: s = Section.objects.get() s.magazine.id will still return the mangazine id, but it will also query the database twice. Once to get the Section object, then second time to get the details fo the magazine object. Assuming that you want to put this into a form, you'll probably have to do something like: new_data['magazine'] = s.magazine.id in the forms page. Hope that this helps. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Updating multiple models with one form submission
I can't say that I know the answer since I haven't tried it, yet. In the example that I referenced, the fields were defined and set in the manipulator class. You might be able to to do this as two different forms, that appear on the same page, the javascript may update an ingredient model through javascript, and the other fields could be updated in the form. Honestly, this is just conjecture. It's an interesting problem that I'll have to test out, when I have some time. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Updating multiple models with one form submission
You can modify multiple models with the same view. I've managed to do it, but involved creating my own manipulator. This isn't nearly as scarry as it sounds, once you understand what's going on. I posted what I did on a http://ssy5.blogspot.com/2006/11/taking-care-of-registration.html";>blog . The example is for adding registration information, where the user needs to create an organization as well. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: missing auth_user_group and auth_group_permissions tables
Thanks for the advice. I've checked that the settings.py file was saved before syncing the database. The correct setting file is getting loaded. And finally there is no problem with the PYTHONPATH. The project is the first one shown when using '>>>sys.path'. The tables that were created were: auth_group auth_message auth_permission auth_user django_admin_log django_content_type django_session django_site So I can't quite figure out why it's not creating the auth_user_group and the auth_group_permissions tables. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: model question
In the view you would need to check if the voter has already voted in the poll. If the query is empty, then you can allow the person to vote, if the query contains a record for a particular poll and a particular voter, then you need to redirect them to an "You've already voted on this poll" page. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: So I made a forum with Django
As I'm relatively new to Django (I'm still reading through tutorials and documentation), I was wondering how you managed user authentication. I know that it can be managed throught the auth package, but I was curious how you specifically handled it because I think it was pretty neat. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
creating a super user
I'm currently working through the tutorial using the lastest development verison of django, downloaded from subversion. I've installed django on an Ubuntu 6.06 linux box, and was wondering why I wasn't prompted to create a super user account when I first tryed '>manage.py syncdb'. I ask, because I can't seem to get into the admin side of the tutorial project at all. Thanks for any help in advance. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---