Hey Nik,

Thanks for the detailed explanation. It is clear now.

Thanks,
Smaran

On Tue, Jul 3, 2012 at 5:47 PM, Nikolas Stevenson-Molnar <
[email protected]> wrote:

>  Hi Smaran,
>
> Yes, by full path, I mean, for example, 'polls.urls'. And yes, it is a
> string. Django interprets it as a module path when it builds up the URLs.
> It's the same thing that happens in the polls.urls module when mapping the
> URL patterns to functions. The functions are all quoted as well (in the
> tutorial). In this case, you *don't* need to give the full path, since
> the 'polls.views' part is specified as the first argument of patterns. For
> example, looking at the last code snippet on the page you linked to, you
> could write the URL patterns in a few different ways:
>
> 1) as-is
> 2) with no 'prefix' given:
> urlpatterns = patterns('',
>     url(r'^$', 'polls.views.index'),
>     ...
> )
>
> 3) with a partial prefix:
> urlpatterns = patterns('polls',
>     url(r'^$', 'views.index'),
>     ...
> )
>
> 4) by passing in the function itself, rather than a string
> from polls.views import index
> ...
> urlpatterns = patterns('',
>     url(r'^$', index),
>     ...
> )
>
> This notion of using strings instead of actual references is used
> elsewhere too. For example, if you need to create a ForeignKey field in one
> model that references a model defined later in the same file:
> https://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey (see
> first ForeignKey code example). It's also used in the settings file (all
> the apps and middleware classes are provided as strings; typically nothing
> is imported in the settings module).
>
> Does that make sense at all? In short, in many places where Django
> requires a function, class, or module, you can provide a direct reference
> to it, or provide a string instead. You'll still get an error if the module
> path in that string is not correct.
>
> _Nik
>
>
> On 7/3/2012 5:14 PM, Smaran Harihar wrote:
>
> Hey Nik,
>
>  Thanks for the reply. When you say, provide full path for the lazy
> quoted version, do you mean 'polls.url' ?
> Is that not relative path?
>
>  Also having the path in quotes 'polls.url', is it not a string?
>
>  Thanks,
> Smaran
>
> On Tue, Jul 3, 2012 at 5:02 PM, Nikolas Stevenson-Molnar <
> [email protected]> wrote:
>
>>  If I understand correctly, you're asking about the difference between
>> include('polls.urls') and include(admin.site.urls)? Django will often let
>> you reference modules, functions, and classes 'lazily', meaning you don't
>> need to import them first. You could use the unquoted version for polls as
>> well, it would look something like
>>
>> import polls
>> ...
>> url(r'^polls/', include(polls.urls))
>>
>> *or*
>>
>> from polls import urls as poll_urls
>> ...
>> url(r'^polls/', include(poll_urls))
>>
>> Note that if you're using the 'lazy', quoted version you always need to
>> provide the full path.
>>
>> _Nik
>>
>>
>> On 7/3/2012 4:24 PM, Smaran Harihar wrote:
>>
>>  Hi Djangoers,
>>
>>  I just completed the tutorial 3 and got a little confused on the last
>> section<https://docs.djangoproject.com/en/dev/intro/tutorial03/#decoupling-the-urlconfs>of
>>  the tutorial,
>>
>>   urlpatterns = patterns('',
>>     url(r'^polls/', include('polls.urls')),
>>     url(r'^admin/', include(admin.site.urls)),)
>>
>> In this for the polls app, we are assigning the urls.py path in the
>> quotes 'polls.urls'
>> but for admin we are not?
>>
>>  So what is the difference and being it quotes how does it still pick up
>> the path? Does django not consider it to be simply string.
>>
>>  --
>> Thanks & Regards
>> Smaran Harihar
>>
>>   --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to [email protected].
>> 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.
>>
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to [email protected].
>> 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.
>>
>
>
>
>  --
> Thanks & Regards
> Smaran Harihar
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> 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.
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> 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.
>



-- 
Thanks & Regards
Smaran Harihar

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
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.

Reply via email to