Re: html to a database.
Hi, I'm not sure but pls check it out the following links 1. http://www.mercurytide.co.uk/news/article/django-full-text-search/ 2. http://pkarl.com/articles/guide-django-full-text-search-sphinx-and-django-sp/ Thanks & Regards, Jiffin Joy Akkarappatty. On Mon, Feb 8, 2010 at 7:37 AM, har wrote: > Hi all, > > do you know the most efficient way to put the content of an html file > into a > mySQL database? > > 1.- I have the html document in my hard disk. > 2.- Then I Open the file > 3.- Read the content > 4.- Write all the content it in a SQL db > > I am using scrapy to crawl through the websites and then i want to put > the data that i collect to a database. I have gone through the > tutorial but couldn't find much about it...i was thinking of using > django beacuse of its capabilities... > > Any help appreciated > > > Thanks! > > harshit > > -- > 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. > > -- 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.
Creating an external url in the django admin section
Hi all. If someone could please help me as I am very new to django and getting desperate for help. The issue is as follows: For one of my apps in 'INSTALLED APPS' I need to add a link in the admin section that will cause the stats to be downloaded. The URL for this link is /questionnaire/export_csv. How can I define such a link please? Thank you for your help. This is the template but as you will see this creates the link for the questionnaire/export_csv, but it does create the link for every single app instead of just for the Questionnaire app. admin_index.py {% extends "admin/base_site.html" %} {% load i18n %} {% block stylesheet %}{% load adminmedia %}{% admin_media_prefix %}css/ base.css{% endblock %} {% block coltype %}colMS{% endblock %} {% block bodyclass %}{% endblock %} {% block breadcrumbs %}{% endblock %} {% block content %} {% if app_list %} {% for app in app_list %} {% blocktrans with app.name as name %}{{ name }}{% endblocktrans %} {% for model in app.models %} {% if model.perms.change %} {{ model.name }} {% else %} {{ model.name }} {% endif %} {% if model.perms.add %} {% trans 'Add' %} {% else %} {% endif %} {% if model.perms.change %} {% trans 'Change' %} {% else %} {% endif %} {% endfor %} Export-to- CSV {% endfor %} {% else %} {% trans "You don't have permission to edit anything." %} {% endif %} {% endblock %} {% block sidebar %} {% trans 'Recent Actions' %} {% trans 'My Actions' %} {% load log %} {% get_admin_log 10 as admin_log for_user user %} {% if not admin_log %} {% trans 'None available' %} {% else %} {% for entry in admin_log %} {% if not entry.is_deletion %}{% endif %}{{ entry.object_repr| escape }}{% if not entry.is_deletion %}{% endif %}{% filter capfirst %}{% trans entry.content_type.name %}{% endfilter %} {% endfor %} {% endif %} {% endblock %} -- 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: Next previous links from a query set / generi views
On Feb 8, 2010, at 7:56 AM, eaman wrote: I'm up to code those two methods... If some one is interested in this thread I managed to code these two methods: get_next | get_prev in order to get a previous or next item in a set right from my model: - http://dpaste.com/155961/ Now that you've got a date attribute, why not use that for next and previous? If you don't want to do that, you still might consider returning a real object instance, and then giving the model a get_absolute_url() method and calling that in the template. That will save you hardcoding the links in the template. But if it's just an id you want, the following might be more efficient: def get_next(self): all_ids = Foto.objects.filter(galleria = self.galleria, id__gt=self.id).values_list("id",flat=True).order_by("id") try: return min(all_ids) except ValueError: return None Then reverse that (id__lt=self.id and use the max python function) for get_prev() Hope that's helpful, Eric - Is there a better way to get the highest 'previous' item then using aggregate(Max('id'))? - I guess the if /else conditional loop that should check the existence of the prev | next item is suboptimal... /eaman -- 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 . -- 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.
html to a database.
Hi all, do you know the most efficient way to put the content of an html file into a mySQL database? 1.- I have the html document in my hard disk. 2.- Then I Open the file 3.- Read the content 4.- Write all the content it in a SQL db I am using scrapy to crawl through the websites and then i want to put the data that i collect to a database. I have gone through the tutorial but couldn't find much about it...i was thinking of using django beacuse of its capabilities... Any help appreciated Thanks! harshit -- 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: Deserializing xml or json goes into infinite recursion
The top of the traceback might also help with figuring this out: In [4]: objs = [obj for obj in serializers.deserialize('xml',data)] --- RuntimeError Traceback (most recent call last) /Users/schwehr/projects/src/raphub/ in () /sw32/lib/python2.6/site-packages/django/core/serializers/ xml_serializer.pyc in next(self) 129 if event == "START_ELEMENT" and node.nodeName == "object": 130 self.event_stream.expandNode(node) --> 131 return self._handle_object(node) 132 raise StopIteration 133 /sw32/lib/python2.6/site-packages/django/core/serializers/ xml_serializer.pyc in _handle_object(self, node) 178 179 # Return a DeserializedObject so that the m2m data has a place to live. --> 180 return base.DeserializedObject(Model(**data), m2m_data) 181 182 def _handle_fk_field_node(self, node, field): /sw32/lib/python2.6/site-packages/django/db/models/base.pyc in __init__(self, *args, **kwargs) 311 setattr(self, field.name, rel_obj) 312 else: --> 313 setattr(self, field.attname, val) 314 315 if kwargs: /sw32/lib/python2.6/site-packages/django/db/models/base.pyc in _set_pk_val(self, value) 375 376 def _set_pk_val(self, value): --> 377 return setattr(self, self._meta.pk.attname, value) 378 379 pk = property(_get_pk_val, _set_pk_val) On Feb 7, 2:28 pm, Kurt Schwehr wrote: > Hi All, > > I'm attempting to pull data from an older django server (0.9x) into a > django 1.1.1 app. I get an infinite recursion error with either the > json or xml data. Is this a problem with version skew and the formats > of serialize/deserialize or do I likely have a coding error on my > part? > > This is using django 1.1.1 with python 2.6 and sqlite3 from fink on > macosx 10.6 > > Any help would be greatly appreciated. > > Thanks!> -- 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: No module named urls
On Sun, Feb 7, 2010 at 4:27 PM, Brian wrote: > Hi all, > > I'm putting together a Django application from scratch and have > created my models. I'm trying to activate the admin site now and am > getting the above error. I've tried everything I found on mailing > lists with no luck. This includes the old style settings.py (which is > commented out now) as well as the new. Note, the model has synced to > the database correctly. > > Here is the contents of the admin.py file which resides in my app > directory (triagedb/triagedb_app): > > [snip] > Here is my settings file: > [snip] > > ROOT_URLCONF = 'triagedb_app.urls' > > [snip] > > INSTALLED_APPS = ( >#'django.contrib.auth', >#'django.contrib.contenttypes', >'django.contrib.sessions', >'django.contrib.sites', >'django.contrib.admin', >'triagedb.triagedb_app', > ) > > Here is my urls..py file: > [snip] > The urls.py file you show looks like it is a base project urls.py file, auto-created perhaps when you ran django-admin.py startproject triagedb. That file would have been place in triagedb/urls.py. Yet your ROOT_URLCONF settings is ''triagedb_app.urls", which will be looking to load triagedb_app/urls.py from somewhere in the Python path. Where exactly is this urls.py file located? If it is really in triagedb/urls.py then the URLCONF setting should be 'triagedb.urls'. Karen -- 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: geodjango Point distance
http://code.google.com/apis/maps/articles/phpsqlsearch.html I know this is php but it does a good job of explaining make sure to test the distance from one point to itself the geometric functions have upper and lower limits Sent from my Verizon Wireless BlackBerry -Original Message- From: Evan Bowling Date: Sun, 7 Feb 2010 15:20:32 To: Django users Subject: geodjango Point distance Hey all, I am trying to calculate the spherical and spheroidal distance between two points that aren't stored within any model. I found this post from a few years ago and was wondering if it was resolved: http://www.mail-archive.com/django-users@googlegroups.com/msg40120.html >>> from django.contrib.gis.geos import Point >>> print Point(-84,42).distance( Point(-80, 45) ) # yields 5.0 which still >>> corresponds to purely triangular distance -- 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. -- 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: Next previous links from a query set / generi views
> I'm up to code those two methods... If some one is interested in this thread I managed to code these two methods: get_next | get_prev in order to get a previous or next item in a set right from my model: - http://dpaste.com/155961/ - Is there a better way to get the highest 'previous' item then using aggregate(Max('id'))? - I guess the if /else conditional loop that should check the existence of the prev | next item is suboptimal... /eaman -- 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: Callback method on session timeout
I have a cpu intensive process that only runs when a user logs in. Once they log out or session time out I need to stop this process Sent from my Verizon Wireless BlackBerry -Original Message- From: cootetom Date: Sun, 7 Feb 2010 15:21:58 To: Django users Subject: Re: Callback method on session timeout What is the problem you are trying to solve with this? On Feb 7, 12:08 am, adamjamesdrew wrote: > Does django have the ability to do a callback when a session time out > occurs? -- 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. -- 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.
geodjango Point distance
Hey all, I am trying to calculate the spherical and spheroidal distance between two points that aren't stored within any model. I found this post from a few years ago and was wondering if it was resolved: http://www.mail-archive.com/django-users@googlegroups.com/msg40120.html >>> from django.contrib.gis.geos import Point >>> print Point(-84,42).distance( Point(-80, 45) ) # yields 5.0 which still >>> corresponds to purely triangular distance -- 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.
No module named urls
Hi all, I'm putting together a Django application from scratch and have created my models. I'm trying to activate the admin site now and am getting the above error. I've tried everything I found on mailing lists with no luck. This includes the old style settings.py (which is commented out now) as well as the new. Note, the model has synced to the database correctly. Here is the contents of the admin.py file which resides in my app directory (triagedb/triagedb_app): from triagedb.triagedb_app.models import Address, TriageGroup, Nurse, PhysGroup, Physician from django.contrib import admin admin.site.register(Address) admin.site.register(TriageGroup) admin.site.register(Nurse) admin.site.register(PhysGroup) admin.site.register(Physician) Here is my settings file: # Django settings for triagedb_app project. DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Name', 'your_em...@domain.com'), ) MANAGERS = ADMINS DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', # 'sqlite3' or 'oracle'. DATABASE_NAME = '/Users/Tarka/triagedb/triagedb.sqlite' # Or path to database file if # using sqlite3. DATABASE_USER = 'triagedb_app' # Not used with sqlite3. DATABASE_PASSWORD = 'triageapp#1' # Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. DATABASE_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. # If running in a Windows environment this must be set to the same as your # system time zone. TIME_ZONE = 'America/Vancouver' # 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 # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" MEDIA_ROOT = '' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash if there is a path component (optional in other cases). # Examples: "http://media.lawrence.com";, "http://example.com/media/"; MEDIA_URL = '' # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a # trailing slash. # Examples: "http://foo.com/media/";, "/media/". ADMIN_MEDIA_PREFIX = '/media/' # Make this unique, and don't share it with anybody. SECRET_KEY = '[edited]' # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', # 'django.template.loaders.eggs.load_template_source', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', ) ROOT_URLCONF = 'triagedb_app.urls' TEMPLATE_DIRS = ( # 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.admin', 'triagedb.triagedb_app', ) Here is my urls..py file: from django.conf.urls.defaults import * # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Example: # (r'^triagedb_app/', include('triagedb_app.foo.urls')), # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: # (r'^admin/', include(admin.site.urls)), (r'^admin/(.*)', admin.site.root), ) And finally, here is the error message: Traceback (most recent call last): File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/django/core/servers/basehttp.py", line 279, in run self.result = application(self.environ, self.start_response) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/django/core/servers/basehttp.py", line 651, in __call__ return self.application(environ, start_response) File "/opt/local/Library/Frameworks/Python.f
Re: Callback method on session timeout
What is the problem you are trying to solve with this? On Feb 7, 12:08 am, adamjamesdrew wrote: > Does django have the ability to do a callback when a session time out > occurs? -- 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: mysql master-master setup
On ma, 2010-02-08 at 00:04 +0100, Henrik Genssen wrote: > what is the best way to setup a master-master replication using mysql > with django? Not to do it :) > Has anyone any experiences with this? I did not use it with django, but I have use master-master (or even rings with more than 2). It's brittle and should not be used. With the new multi-db in django 1.2 it becomes much easier to route read queries to a slave, thus allowing your master to scale a bit further, reducing the need for master-master. If you still want to use it, make sure you set auto-increment-increment and auto-increment-offset properly to try and avoid duplicate keys. -- Dennis K. The universe tends towards maximum irony. Don't push it. -- 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.
mysql master-master setup
HI, what is the best way to setup a master-master replication using mysql with django? Has anyone any experiences with this? Did you use HAProxy in front of mysql? How many connections does django use during one page request / url? (is there a risk, that I hit 2 instances of mysql during one request, where replication has not finished, yet?) Any other hints, I should have an eye on? regards Hinnack -- 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: inputting a request.user into a model on the backend
On Feb 7, 9:26 pm, kamilski81 wrote: > I am trying to set a user on a model, on the back-end. > > u = request.user > g = Goal() > g.user = u > form = GoalForm(request.POST, g) > > I am getting the following error: > goal.user_id may not be NULL What was wrong with the solution I posted in your earlier thread on this same issue (http://groups.google.com/group/django-users/msg/ b4a5615209bd7b06)? -- DR. -- 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.
inputting a request.user into a model on the backend
I am trying to set a user on a model, on the back-end. u = request.user g = Goal() g.user = u form = GoalForm(request.POST, g) I am getting the following error: goal.user_id may not be NULL -- 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: Unit testing Templatetags
Hey! Thanks a lot, that seems obvious now... I found out that doing this: template.libraries['django.templatetags.mytest'] = register I can then use {% load mytest %} ... for the tags. On 7 helmi, 22:19, Rolando Espinoza La Fuente wrote: > You can see example code > here:http://github.com/darkrho/django-dummyimage/blob/master/dummyimage/te... Great example. IMO, there should be more unit-testing examples in Django documentation, templatetags should be one... -- 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: Unit testing Templatetags
On Sun, Feb 7, 2010 at 3:56 PM, Jari Pennanen wrote: [...] > > #print > loader.get_template_from_string(template_content).render(self.context) > print > template.Template(template_content).render(self.context) > > > if __name__ == '__main__': > unittest.main() > > But I keep getting "TemplateSyntaxError: Invalid block tag: 'sometag'" I think you forget the {% load ... %} tag The way that I found on the net to test tags was using Template/Context class. t = Template("{% load mytags %}{% sometag %}") c = Context({}) self.failUnlessEqual(result, t.render(c)) You can see example code here: http://github.com/darkrho/django-dummyimage/blob/master/dummyimage/tests.py#L17 Regards, -- Rolando Espinoza La fuente www.rolandoespinoza.info -- 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.
Unit testing Templatetags
Hi! I decided to try to unit test templatetag using following code: import unittest from django import template from django.template import loader register = template.Library() @register.simple_tag def sometag(arg=None): return "ok" class MyTagTests(unittest.TestCase): def setUp(self): self.context = template.Context() def test_sometag(self): """Test the tag""" template_content = """ {% sometag "some string" %} """ #print loader.get_template_from_string(template_content).render(self.context) print template.Template(template_content).render(self.context) if __name__ == '__main__': unittest.main() But I keep getting "TemplateSyntaxError: Invalid block tag: 'sometag'" As a reference I've been looking on to this http://code.djangoproject.com/browser/django/trunk/tests/othertests/templates.py?rev=3113 only difference I can see is the test_template_loader() function, but is that it? I should also do template_loader to get the tag tests? I would like to know what is the simplest way to do this, there got to be a way to test these without custom template loader... -- 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.
Deserializing xml or json goes into infinite recursion
Hi All, I'm attempting to pull data from an older django server (0.9x) into a django 1.1.1 app. I get an infinite recursion error with either the json or xml data. Is this a problem with version skew and the formats of serialize/deserialize or do I likely have a coding error on my part? This is using django 1.1.1 with python 2.6 and sqlite3 from fink on macosx 10.6 Any help would be greatly appreciated. Thanks! -kurt class alert(models.Model): pk = models.CharField(max_length=10, primary_key=True) zone_id = models.IntegerField() first_good_data = models.DateTimeField() ... from django.core import serializers data = file('nrwbuoys.xml').read() objs = serializers.deserialize('xml',data) o = objs.next() /sw32/lib/python2.6/site-packages/django/db/models/base.pyc in _set_pk_val(self, value) 375 376 def _set_pk_val(self, value): --> 377 return setattr(self, self._meta.pk.attname, value) 378 379 pk = property(_get_pk_val, _set_pk_val) RuntimeError: maximum recursion depth exceeded while calling a Python object Where the xml looks like this: 1970-01-01 00:05:26 ... 32427 DEPLOYED 1 -- 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: uniquely identifying an entry
Every model has a field by the name of "id" which is the primary key of the db table u can use SlugField() for a named unique value. On Thu, Feb 4, 2010 at 11:20 PM, harryos wrote: > hi > (sorry about this newbie question..) > I have designed an entry and a category as follows. > The entry doesn't have a title.(The user is not expected to provide a > title for it )It is uniquely identified by a combination of its > published datetime and the name of the category it belongs to. > > class MyCategory(models.Model): >name=models.CharField(max_length=10) >description=models.TextField() >slug=models.SlugField(unique=True) > >def __unicode__(self): >return self.name > > class MyEntry(models.Model): >posted_time=models.DateTimeField(default=datetime.now) >category=models.ForeignKey(MyCategory) >description=models.TextField() >author=models.ForeignKey(User) > >def __unicode__(self): >return "%s%s"%(self.category.name,self.posted_time) > > I would like to list all entries posted at different minutes in an > hour. and also show the details of a single entry.I am not sure how I > can do this. > > I am wondering if I can get details of an entry like > /myapp/entries/2010/jan/01/10/35/splcat > sothat I can get an entry belonging to 'splcat' posted at 10 hrs,35 > minutes on 1st jan 2010. Is there some way I can do lookup on the > hour,minute of posted_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-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. > > -- 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: problem with get_absolute_url
On Sunday 07 February 2010 10:49:03 jimgardener wrote: > Thanks Mike for the reply. > > I rewrote the method as > @models.permalink > def get_absolute_url(self): > return("myapp_entry_detail",(),{'id':self.id}) > > When I go to the admin interface's edit page for an entry and click > the viewsite button it causes the following error, > NoReverseMatch,Reverse for 'myapp_entry_detail' with arguments '()' > and keyword arguments '{'id': 6}' not found. > > When I try in browser http://127.0.0.1:8000/myapp/1/ causes > ValueError,dictionary update sequence element #0 has length 1; 2 is > required > > is this caused by the name 'myapp_entry_detail' in the urlpattern > below? > (r'^(?P\d+)/$','myapp.views.entry_detail','myapp_entry_detail'), > > The following is the entry_detail method which I defined > def entry_detail(request,id): > entry=MyEntry.objects.get(id=id) > entry_detail_dict={'object':entry} > return render_to_response('myapp/ > myentry_detail.html',entry_detail_dict) > > I can't figure out why these errors are occuring..Everything works > fine when I hardcode the url and omit the name 'myapp_entry_detail' in > the urlpattern.If I don't omit that name in urlpattern ,the Request > URL http://127.0.0.1:8000/myapp/1/ causes the ValueError which I > mentioned earlier. > See the link below and you want your pattern to be like this url(r'^(?P\d+)/$','myapp.views.entry_detail',name='myapp_entry_detail'), Actually read this whole page, but this anchor is the important part, and the reverse() towards the bottom http://docs.djangoproject.com/en/dev/topics/http/urls/#url and for completeness reread through this again: http://docs.djangoproject.com/en/dev/ref/models/instances/#the-permalink- decorator In the end tho, I usually just use the name='' in the url() pattern along with the **kwargs as described before. But make sure you understand those two pages and you should be able to get it working perfect. Mike -- Magnocartic, adj.: Any automobile that, when left unattended, attracts shopping carts. -- Sniglets, "Rich Hall & Friends" signature.asc Description: This is a digitally signed message part.
Re: problem with get_absolute_url
Thanks Mike for the reply. I rewrote the method as @models.permalink def get_absolute_url(self): return("myapp_entry_detail",(),{'id':self.id}) When I go to the admin interface's edit page for an entry and click the viewsite button it causes the following error, NoReverseMatch,Reverse for 'myapp_entry_detail' with arguments '()' and keyword arguments '{'id': 6}' not found. When I try in browser http://127.0.0.1:8000/myapp/1/ causes ValueError,dictionary update sequence element #0 has length 1; 2 is required is this caused by the name 'myapp_entry_detail' in the urlpattern below? (r'^(?P\d+)/$','myapp.views.entry_detail','myapp_entry_detail'), The following is the entry_detail method which I defined def entry_detail(request,id): entry=MyEntry.objects.get(id=id) entry_detail_dict={'object':entry} return render_to_response('myapp/ myentry_detail.html',entry_detail_dict) I can't figure out why these errors are occuring..Everything works fine when I hardcode the url and omit the name 'myapp_entry_detail' in the urlpattern.If I don't omit that name in urlpattern ,the Request URL http://127.0.0.1:8000/myapp/1/ causes the ValueError which I mentioned earlier. Any help will be much appreciated thanks jim -- 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.
Date-based generic views - UTC handling
I have a database model in which the datetime entry of an item is stored as a DateTimeField(). This datetime is stored as UTC. In one of my views, which displays details for each entry, I am converting and formatting the UTC time to PST. I just started using generic views and for "django.views.generic.date_based.archive_month" there is the "date_field" argument which indicates the name of the DateTimeField in the QuerySet's model that the view should use. Is there an easy way to format this date_field to my local time zone i.e. PST? I have also tried using the "date" and "time" filters within the template itself, however, those are still UTC. Any pointers would be appreciated. Wayne -- 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.
How can _meta.local_fields not match the table schema in the database?
I'm completely confused about why _meta.local_fields returns more fields than the database table contains. The User model inherits from contrib.auth.models.User. $ mysql -u user -p database Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1240032 Server version: 5.0.77 Source distribution mysql> describe auth_user; ++--+--+-+- ++ | Field | Type | Null | Key | Default | Extra | ++--+--+-+- ++ | id | int(11) | NO | PRI | NULL| auto_increment | | username | varchar(30) | NO | UNI | NULL || | first_name | varchar(30) | NO | | NULL || | last_name | varchar(30) | NO | | NULL || | email | varchar(75) | NO | | NULL || | password | varchar(128) | NO | | NULL || | is_staff | tinyint(1) | NO | | NULL || | is_active | tinyint(1) | NO | | NULL || | is_superuser | tinyint(1) | NO | | NULL || | last_login | datetime | NO | | NULL || | date_joined| datetime | NO | | NULL || | email_isvalid | tinyint(1) | NO | | NULL || | email_key | varchar(16) | YES | | NULL || | reputation | int(10) unsigned | NO | | NULL || | gravatar | varchar(32) | NO | | NULL || | gold | smallint(6) | NO | | NULL || | silver | smallint(6) | NO | | NULL || | bronze | smallint(6) | NO | | NULL || | questions_per_page | smallint(6) | NO | | NULL || | last_seen | datetime | NO | | NULL || | real_name | varchar(100) | NO | | NULL || | website| varchar(200) | NO | | NULL || | location | varchar(100) | NO | | NULL || | date_of_birth | date | YES | | NULL || | about | longtext | NO | | NULL || ++--+--+-+- ++ 25 rows in set (0.00 sec) >From the Django error page, this is the SQL statement that generates the error: Exception Value: (1110, "Column 'about' specified twice") 'INSERT INTO `auth_user` (`username`, `first_name`, `last_name`, `email`, `password`, `is_staff`, `is_active`, `is_superuser`, `last_login`, `date_joined`, `email_isvalid`, `email_key`, `reputation`, `gravatar`, `gold`, `silver`, `bronze`, `questions_per_page`, `last_seen`, `real_name`, `website`, `location`, `date_of_birth`, `about`, `email_isvalid`, `email_key`, `reputation`, `gravatar`, `gold`, `silver`, `bronze`, `questions_per_page`, `last_seen`, `real_name`, `website`, `location`, `date_of_birth`, `about`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' This SQL statement seems to be generated by iterating over User._meta.local_fields. I don't understand why _meta.local_fields doesn't match the actual User table schema. $ python2.5 manage.py shell Python 2.5.4 (r254:67916, Aug 5 2009, 12:42:40) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from forum.models import User >>> len(User._meta.local_fields) 39 >>> import pprint >>> pprint.pprint(User._meta.local_fields) [, , , , , , , , , , , # here is where customizations to User begin. , , , , , , , , , , , , , , # this seems to be a duplicate of the fields added to User , , , , , , , , , , , , , ] >>> This is how this project customized User: from django.contrib.auth.models import User The additional fields to the model are added thusly: User.add_to_class('email_isvalid', models.BooleanField(default=False)) U
Re: django-authopenid user timeout
Hi Rachel, I can't help your problem but I'm curious after you said "it seems to be working just fine" - how did you manage to make it work? You just followed the site instructions and it works? I got a problem here when i click "register" it will complain that there's missing a parameter on register() and only one was given.. no idea how or where to fix that.. Can you sign in in your app with a gmail login/password as an openid provider? or is it just with openid url? Thanks in advance. I'm really looking forward to make this work. Perhaps I will be able to assist you alter if I use this. On Jan 22, 2:18 am, Rachel Willmer wrote: > I've just installed django-authopenidin a project, and it seems to be > working just fine, apart from one minor issue. > > (The creator of django-authopenidisn't maintaining the project any > more, and there isn't a mailing list, hence why I'm asking this > question here rather than elsewhere.) > > So, as I say, it works fine except the user's login gets timed-out > after a short while, and I'd like to keep people logged in unless they > explicitly logged out. Anyone know how to do this? I can't see any > reference to timeouts in the documentation. > > Actually, I'm not even sure whether this timeout is caused in > django-authopenidor down at the core django level or elsewhere. > > Any pointers very welcome! > Rachel -- 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: Next previous links from a query set / generi views
On Feb 7, 2:56 pm, Eric Abrahamsen wrote: > On Feb 7, 2010, at 8:54 PM, eaman wrote: [CUT] > The lazy option would probably be to add get_next() and get_previous() > methods to your model, that return an instance based on whatever > definition of "next" and "previous" works for you. You might consider > some kind of timestamp field for your model, though – you'd be > surprised how often that comes in handy… Thanks, I've made a try with the free pagination, which is nice and easy but doesn't work out of the box as I would like (but that's probbly me unable to pass an extra parameter to limit the query set...). I'm up to code those two methods, I guess I'll try first to embed them in the model and then to think about of some form of abstraction to use them with others similar models. Generic views are really nice, but I guess it's time for me to dive deeper in models and views. Thanks for the clue. -- 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: problem with get_absolute_url
> Then what you should be returning is the reverse() args, which is the > viewname as a string, > This is wrong, it's the name parameter for the url in urls.py Sorry... Mike -- "One day I woke up and discovered that I was in love with tripe." -- Tom Anderson signature.asc Description: This is a digitally signed message part.
Re: csrf error on login and admin
Ok. Most likely the problem is when nginx is giving me 499 (client timeout) errors. On Feb 7, 3:50 pm, Nixarn wrote: > Hmm apparently doesn't work anymore gah... hrmp. Looking into it. > > Niklas > > On Feb 7, 3:18 pm, Nixarn wrote: > > > > > Having the same problem with the dev version of django. I just can't > > get into the Admin. > > > Works fine in Chrome for some reason but with Firefox or IE I get: > > > 403 Forbidden > > > CSRF verification failed. Request aborted. > > > Reason given for failure: CSRF cookie not set. > > > And I've tried clearing the cache and cookies from the browser. All > > without luck :/ > > > Niklas > > > On Dec 19 2009, 1:38 am, Kenneth Gonsalves wrote: > > > > On Wednesday 16 Dec 2009 10:45:49 am Paddy Joy wrote: > > > > > Try 'django.middleware.csrf.CsrfMiddleware' instead of > > > > 'django.contrib.csrf.middleware.CsrfMiddleware' > > > > copied and pasted straight from the official docs > > > -- > > > regards > > > Kenneth Gonsalves > > > Senior Project Officer > > > NRC-FOSShttp://nrcfosshelpline.in/web/ -- 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: Next previous links from a query set / generi views
On Feb 7, 2010, at 8:54 PM, eaman wrote: On Feb 7, 3:24 am, Eric Abrahamsen wrote: Yup, if you have non-null date/datetime fields on your model, each model will automatically get "get_next_by_FOO" and "get_previous_by_FOO" methods, where FOO is the name of the datetime Well I guess the 'Lazy' optiond is to add a date field to my model and get the free pagination. Or code my own view, of course. The lazy option would probably be to add get_next() and get_previous() methods to your model, that return an instance based on whatever definition of "next" and "previous" works for you. You might consider some kind of timestamp field for your model, though – you'd be surprised how often that comes in handy… Thanks. /eaman [CUT] -- 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 . -- 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: Reversed URLs problem
On Sun, Feb 7, 2010 at 4:12 AM, Daniel Roseman wrote: > If all URLs work both with and without a prefix, it would seem that > you've somehow duplicated your URL definitions somewhere. Could you > post your entire urls.py? Preferably somewhere like dpaste.com. > Also some information about deployment environment might be illuminating. If not the dev server, what exactly, and what sort of config have you set up for it? Karen -- 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: csrf error on login and admin
Hmm apparently doesn't work anymore gah... hrmp. Looking into it. Niklas On Feb 7, 3:18 pm, Nixarn wrote: > Having the same problem with the dev version of django. I just can't > get into the Admin. > > Works fine in Chrome for some reason but with Firefox or IE I get: > > 403 Forbidden > > CSRF verification failed. Request aborted. > > Reason given for failure: CSRF cookie not set. > > And I've tried clearing the cache and cookies from the browser. All > without luck :/ > > Niklas > > On Dec 19 2009, 1:38 am, Kenneth Gonsalves wrote: > > > > > On Wednesday 16 Dec 2009 10:45:49 am Paddy Joy wrote: > > > > Try 'django.middleware.csrf.CsrfMiddleware' instead of > > > 'django.contrib.csrf.middleware.CsrfMiddleware' > > > copied and pasted straight from the official docs > > -- > > regards > > Kenneth Gonsalves > > Senior Project Officer > > NRC-FOSShttp://nrcfosshelpline.in/web/ -- 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: csrf error on login and admin
Might have gotten somewhere with this. I'm using nginx and rewriting urls with www to be without www. And in firefox I seem to be getting the following weirdness in firebug: domainname.com, status: timeout, domain: domainname.com, size: 1.8kb, time: 26ms domainname.com, status: 200 OK, domain: domainname.com, size: 1.8kb, time: 146ms So the request gets a timeout after 26ms for some bizzar reason. I remoed the rewrite rules and were able to log in to admin with firefox. Niklas On Feb 7, 3:18 pm, Nixarn wrote: > Having the same problem with the dev version of django. I just can't > get into the Admin. > > Works fine in Chrome for some reason but with Firefox or IE I get: > > 403 Forbidden > > CSRF verification failed. Request aborted. > > Reason given for failure: CSRF cookie not set. > > And I've tried clearing the cache and cookies from the browser. All > without luck :/ > > Niklas > > On Dec 19 2009, 1:38 am, Kenneth Gonsalves wrote: > > > > > On Wednesday 16 Dec 2009 10:45:49 am Paddy Joy wrote: > > > > Try 'django.middleware.csrf.CsrfMiddleware' instead of > > > 'django.contrib.csrf.middleware.CsrfMiddleware' > > > copied and pasted straight from the official docs > > -- > > regards > > Kenneth Gonsalves > > Senior Project Officer > > NRC-FOSShttp://nrcfosshelpline.in/web/ -- 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: csrf error on login and admin
Having the same problem with the dev version of django. I just can't get into the Admin. Works fine in Chrome for some reason but with Firefox or IE I get: 403 Forbidden CSRF verification failed. Request aborted. Reason given for failure: CSRF cookie not set. And I've tried clearing the cache and cookies from the browser. All without luck :/ Niklas On Dec 19 2009, 1:38 am, Kenneth Gonsalves wrote: > On Wednesday 16 Dec 2009 10:45:49 am Paddy Joy wrote: > > > Try 'django.middleware.csrf.CsrfMiddleware' instead of > > 'django.contrib.csrf.middleware.CsrfMiddleware' > > copied and pasted straight from the official docs > -- > regards > Kenneth Gonsalves > Senior Project Officer > NRC-FOSShttp://nrcfosshelpline.in/web/ -- 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.
Decorator problem
I'm trying to make a decorator that checks if a user is staff and redirects to the login page if not logged in or returns a 403 for logged in users that aren't staff. I found permission_required_with_403 (http://www.djangosnippets.org/ snippets/254/) which works well so I've added is_staff_with_403 as below. When I try to use it I get the error at the bottom of this post. from django.contrib.auth import REDIRECT_FIELD_NAME from django.shortcuts import render_to_response from django.template import RequestContext from django.http import HttpResponseRedirect def user_passes_test_with_403(test_func, login_url=None): """ Decorator for views that checks that the user passes the given test. Anonymous users will be redirected to login_url, while users that fail the test will be given a 403 error. """ if not login_url: from django.conf import settings login_url = settings.LOGIN_URL def _dec(view_func): def _checklogin(request, *args, **kwargs): if test_func(request.user): return view_func(request, *args, **kwargs) elif not request.user.is_authenticated(): return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, request.get_full_path())) else: resp = render_to_response('403.html', context_instance=RequestContext(request)) resp.status_code = 403 return resp _checklogin.__doc__ = view_func.__doc__ _checklogin.__dict__ = view_func.__dict__ return _checklogin return _dec def permission_required_with_403(perm, login_url=None): """ Decorator for views that checks whether a user has a particular permission enabled, redirecting to the log-in page or rendering a 403 as necessary. """ return user_passes_test_with_403(lambda u: u.has_perm(perm), login_url=login_url) def is_staff_with_403(login_url=None): """ Decorator for views that checks whether a user is_staff, redirecting to the log-in page or rendering a 403 as necessary. """ return user_passes_test_with_403(lambda u: u.is_staff(), login_url=login_url) Here's the line from my urlconf url(r'^mymodel/add$', views.my_model_add, name='my_model_add'), Here's the error I get Traceback (most recent call last): File "/Users/peter/.virtualenvs/dive/lib/python2.5/site-packages/ django/core/servers/basehttp.py", line 279, in run self.result = application(self.environ, self.start_response) File "/Users/peter/.virtualenvs/dive/lib/python2.5/site-packages/ django/core/servers/basehttp.py", line 651, in __call__ return self.application(environ, start_response) File "/Users/peter/.virtualenvs/dive/lib/python2.5/site-packages/ django/core/handlers/wsgi.py", line 245, in __call__ response = middleware_method(request, response) File "/Users/peter/.virtualenvs/dive/lib/python2.5/site-packages/ django/middleware/common.py", line 83, in process_response if response.status_code == 404: AttributeError: 'function' object has no attribute 'status_code' Since both user.has_perm and user.is_staff both are boolean they should be interchangeable so I don't understand why I'm getting this error, and I don't know how to remedy it. -- 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: Next previous links from a query set / generi views
On Feb 7, 3:24 am, Eric Abrahamsen wrote: > Yup, if you have non-null date/datetime fields on your model, each > model will automatically get "get_next_by_FOO" and > "get_previous_by_FOO" methods, where FOO is the name of the datetime Well I guess the 'Lazy' optiond is to add a date field to my model and get the free pagination. Or code my own view, of course. Thanks. /eaman [CUT] -- 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: problem with get_absolute_url
On Sunday 07 February 2010 01:01:22 jimgardener wrote: > def get_absolute_url(self): > return ('myapp_entry_detail',[self.id]) > Try this @models.permalink def get_abosulte_url(self): return ("myapp_entry_detail", (), {'id': self.id}) --- @models.permalink is the decorator version of the get_absolute_url=... Then what you should be returning is the reverse() args, which is the viewname as a string, the *args and **kwargs -- you could do (self.id) instead of the kwargs, but if you do that it should look like: ("myapp_entry_detail", (self.id), {}) I prefer kwargs for readability. Mike -- Interestingly enough, since subroutine declarations can come anywhere, you wouldn't have to put BEGIN {} at the beginning, nor END {} at the end. Interesting, no? I wonder if Henry would like it. :-) --lwall signature.asc Description: This is a digitally signed message part.
Re: Reversed URLs problem
On Feb 7, 1:12 am, adambossy wrote: > Hi folks, I'm having trouble with reversed urls when they are being > called as template tags. I posted my question on Stack Overflow last > week with no adequate responses. I'll copy it here (with slight > modifications) for convenience. > > http://stackoverflow.com/questions/2189119/project-name-inserted-auto... > > I have my urls named like so in my root urls.py file... > > ... > url(r'^login/$', 'login', name='site_login'), > ... > > This allows me to access /login at my site's root. I have my template > tag defined like so... > > ... > > ... > > It works fine, except that Django automatically resolves that url as / > myprojectname/login, not /login. Both urls are accessible. Only one is > defined. Why is the projectname being inserted to the url > automagically? This occurs for all url tags, not just this one. > > Thanks, > Adam If all URLs work both with and without a prefix, it would seem that you've somehow duplicated your URL definitions somewhere. Could you post your entire urls.py? Preferably somewhere like dpaste.com. -- DR. -- 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: Getting endless redirects when accessing root url
On za, 2010-02-06 at 07:52 -0800, Jan wrote: > urlpatterns = patterns('', > (r'^/$', flatpage, { 'url' : 'home/' } ), ^/$ should be ^$ -- Dennis K. The universe tends towards maximum irony. Don't push it. -- 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.
problem with get_absolute_url
hi I am new to django..and was trying out the permalink method I have defined a get_absolute_url for my Entry class and used permalink. class MyEntry(models.Model): pub_time=models.DateTimeField(default=datetime.now) mycategory=models.ForeignKey() def __unicode__(self): return "%s%s"%(self.mycategory.name,self.pub_time) def get_absolute_url(self): return ('myapp_entry_detail',[self.id]) get_absolute_url=models.permalink(get_absolute_url) In my urls/entries.py I have given these url mappings (r'^(?P\d+)/$' ,'myapp.views.entry_detail','myapp_entry_detail'), (r'^$','myapp.views.entry_archive_index'), and in the archive template am using the get_absolute_url like {% for x in object_list %} {{x}} {% endfor %} where object_list is passed to the template in entry_index method def entry_archive_index(request): entryset=MyEntry.objects.all() entry_info={'object_list' : entryset} return render_to_response('myapp/myentry_archive.html',entry_info) Still when the archive page shows all the created entries,the link on them doesn't point to the entry detail url which should be like myapp/ 1/ where 1 is the id of created entry. (When I hardcode 'return "/myapp/%i/"% self.id ' in the get_absolute_url of the class ,it works.But I know that is not the correct way ) When I checked the source of archive page the url part looks like this MyCat2009-12-27 01:00:36 Can someone give me some pointer to correct this? thanks jim -- 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: Pulling a user to save a form
On Feb 6, 10:11 pm, kamilski81 wrote: > No I am not, once the user is logged in I just want to pull the user > from there...sort of like this > > if request.method == 'POST': > instance = request.user > goal = Goal(user=instance) > form = GoalForm(request.POST, goal) > if form.is_valid(): > form.save() > > and i'm getting the following error still.cause i'm not setting > the user_id on the front-end but only on the back-end. > (1048, "Column 'user_id' cannot be null") > > Thanks for the quick responses so far. If the user field is not in request.POST, it will be set to None on form save. The easiest thing to do is this: goal = form.save() goal.user = user goal.save() -- DR. -- 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.