New to Django. Trying to wrap my head around markdown to html conversion using regex

2020-02-20 Thread Joey Jo Jo Jr
Hello all,

I'm working on a class assignment, so I'm not seeking a specific 
answer/code, but I'm just trying to figure out a general process.

The task is this...

I have some markdown files located in a directory, however when running the 
website they need to be displayed as html.  Because this is a learning 
assignment, no markdown conversion libraries are allowed.

So I'm tasked with using regular expressions to convert.  I understand 
regular expressions and have already formulated a few to change things like 
**text** to text and so on, but being so new to Django and 
still figuring out how it works, I'm just completely flummoxed on the 
execution/implementation.

So any general advice would be appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4d3fe147-d502-40c2-a866-d72bb30f8352%40googlegroups.com.


Re: Write urls without regex in DRF

2019-05-23 Thread nm
Yes, it's possible to write this code without using regexp, and it should 
work the same.

If you have a look at the source code of the routers, there's a method 
`get_urls` in SimpleRouter (you can find it here 
https://github.com/encode/django-rest-framework/blob/master/rest_framework/routers.py),
 
which, among others, does:

regex = route.url.format(
prefix=prefix,
lookup=lookup,
trailing_slash=self.trailing_slash
)


where `route.url` is something like 

url=r'^{prefix}/{lookup}{trailing_slash}$',


and `prefix` is the first argument you pass to `router.register` - in your 
case, an empty string:

def register(self, prefix, viewset, basename=None, base_name=None)


It does not seem to matter whether you put `prefix=r''` or `prefix=''`, the 
ultimate url regex looks the same.
Disclaimer: I assume you're using the latest version of DRF (3.9.x); I 
haven checked how the code looks in older versions. 

On Wednesday, 22 May 2019 17:20:20 UTC+2, Rounak Jain wrote:

>
> I am using DRF Viewsets to auto-generate URLs for different views. Is it 
> possible to write the code below without using regex?
> Thanks
>
> from .views import TaskViewSet
> from rest_framework.routers import DefaultRouter
>
> router = DefaultRouter()
> router.register(r'', TaskViewSet, basename='task')
> urlpatterns = router.urls
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e929c4c9-a174-434d-bda9-9000e5cf8892%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Write urls without regex in DRF

2019-05-22 Thread Rounak Jain

I cannot see any reply 
On Thursday, May 23, 2019 at 7:56:54 AM UTC+5:30, Kevin Jay wrote:
>
> kevin@kjay,net
>
> On Wed, May 22, 2019 at 10:19 AM Rounak Jain  > wrote:
>
>>
>> I am using DRF Viewsets to auto-generate URLs for different views. Is it 
>> possible to write the code below without using regex?
>> Thanks
>>
>> from .views import TaskViewSet
>> from rest_framework.routers import DefaultRouter
>>
>> router = DefaultRouter()
>> router.register(r'', TaskViewSet, basename='task')
>> urlpatterns = router.urls
>>
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CANNuxWNoPGePbAcxnWqzMgeioYXKXwD1Yn-H_2-FN774MdsbbQ%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CANNuxWNoPGePbAcxnWqzMgeioYXKXwD1Yn-H_2-FN774MdsbbQ%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6a1efd52-570c-445f-b4d8-61cd13ae67d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Write urls without regex in DRF

2019-05-22 Thread Kevin Jay
kevin@kjay,net

On Wed, May 22, 2019 at 10:19 AM Rounak Jain  wrote:

>
> I am using DRF Viewsets to auto-generate URLs for different views. Is it
> possible to write the code below without using regex?
> Thanks
>
> from .views import TaskViewSet
> from rest_framework.routers import DefaultRouter
>
> router = DefaultRouter()
> router.register(r'', TaskViewSet, basename='task')
> urlpatterns = router.urls
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANNuxWNoPGePbAcxnWqzMgeioYXKXwD1Yn-H_2-FN774MdsbbQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CANNuxWNoPGePbAcxnWqzMgeioYXKXwD1Yn-H_2-FN774MdsbbQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEtabwdw6%2BZofc4dLdHbvMM9nzdMc0Yd_uCqUnFNWAHE2wn9ug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Write urls without regex in DRF

2019-05-22 Thread Rounak Jain
Thanks for the reply. I understand how to use them in urls.py when creating
normal routes but here in case of drf, it would help if you could show me
how to do it

On Wed, May 22, 2019 at 10:11 PM Onasanya Tunde 
wrote:

> Use Django2.X
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/67314c66-6d50-4390-80de-67d8151fe9a0%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANNuxWNacKstGmD2jwy3r3NYKf_R4BtoqMTBiBoTEaDAL5eb-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Write urls without regex in DRF

2019-05-22 Thread Onasanya Tunde
Use Django2.X

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/67314c66-6d50-4390-80de-67d8151fe9a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Write urls without regex in DRF

2019-05-22 Thread Rounak Jain
I am using DRF Viewsets to auto-generate URLs for different views. Is it
possible to write the code below without using regex?
Thanks

from .views import TaskViewSet
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register(r'', TaskViewSet, basename='task')
urlpatterns = router.urls

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANNuxWNoPGePbAcxnWqzMgeioYXKXwD1Yn-H_2-FN774MdsbbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to construct reversible url names in urls.py using , regex etc

2018-06-25 Thread Mikkel Kromann
Thank you so much for your help, Melvyn.
With your help I managed to the the code running :)
Here it is, if somebody should find it helpful.

cheers, Mikkel

>From somewhere, e.g. models.py
# The list of model names (just add your model names to it)
def GetItemNames():
return [ 'Year', 'Vintage', 'Region', 'Location' ] 

# The generator of paths
def GetItemPaths():
paths = [ ]
for i in GetItemNames():
m = apps.get_model('items', i)
paths.append(path( 'list/'+i+'/' , ItemListView.as_view(
model=m),  name=i+'_list'   ) )
paths.append(path( 'create/'+i+'/',ItemCreateView.as_view(
model=m),name=i+'_create' ) )
paths.append(path( 'update/'+i+'//',   ItemUpdateView.as_view(
model=m),name=i+'_update' ) )
paths.append(path( 'delete/'+i+'//',   ItemDeleteView.as_view(
model=m),name=i+'_delete' ) )

return paths

>From urls.py:
from . models import GetItemPaths
urlpatterns = GetItemPaths() + [
path('/to/some/other/views/'otherview.asView(), name='other_name'),
]




lørdag den 23. juni 2018 kl. 15.08.04 UTC+2 skrev Melvyn Sopacua:
>
> On zaterdag 23 juni 2018 14:30:08 CEST Mikkel Kromann wrote: 
>
> > In models.py: 
> > def GetItemPaths():paths = [ ] 
> > for i in [ 'Model1', 'Model2', 'Model3' ]: 
> > p = path( i + '/list/', ItemListView.as_view(model=i), name=i + 
> > '_list' ) 
> > paths.append(p) 
> > 
> > return paths 
> > 
> > However, there seems to be a problem with trying to pass the model name 
> to 
> > my CBV ItemListView. 
> > Unless I replace the model=i with e.g. model=Model1 I get the following 
> > error: 
> > 
> > 'str' object has no attribute '_default_manager' 
> > 
> > 
> > So it certainly seems that using model=i will not pass the model name. 
> > Is this because the argument for model= expects not a string but an 
> object? 
>
> Yes. You can use import_module from django.functional to pass a dotted 
> path. 
> Or you can use apps.get_model() to get a model class for a app name / 
> model 
> name combo. 
>
> -- 
> Melvyn Sopacua 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/72b5c5e6-b07d-41b8-a9b5-6a471ffe65cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to construct reversible url names in urls.py using , regex etc

2018-06-23 Thread Melvyn Sopacua
On zaterdag 23 juni 2018 14:30:08 CEST Mikkel Kromann wrote:

> In models.py:
> def GetItemPaths():paths = [ ]
> for i in [ 'Model1', 'Model2', 'Model3' ]:
> p = path( i + '/list/', ItemListView.as_view(model=i), name=i +
> '_list' )
> paths.append(p)
> 
> return paths
> 
> However, there seems to be a problem with trying to pass the model name to
> my CBV ItemListView.
> Unless I replace the model=i with e.g. model=Model1 I get the following
> error:
> 
> 'str' object has no attribute '_default_manager'
> 
> 
> So it certainly seems that using model=i will not pass the model name.
> Is this because the argument for model= expects not a string but an object?

Yes. You can use import_module from django.functional to pass a dotted path. 
Or you can use apps.get_model() to get a model class for a app name / model 
name combo.

-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2271710.2KSSaTsjz5%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to construct reversible url names in urls.py using , regex etc

2018-06-23 Thread Mikkel Kromann
So, I think I have a neat idea for solving my problem, simply make a 
function which returns a list of path() returns.

In urls.py
urlpatterns = GetItemPaths() + [
# other paths
]

In models.py:
def GetItemPaths():paths = [ ]
for i in [ 'Model1', 'Model2', 'Model3' ]:
p = path( i + '/list/', ItemListView.as_view(model=i), name=i + 
'_list' )
paths.append(p) 

return paths

However, there seems to be a problem with trying to pass the model name to 
my CBV ItemListView.
Unless I replace the model=i with e.g. model=Model1 I get the following 
error:

'str' object has no attribute '_default_manager'


So it certainly seems that using model=i will not pass the model name.
Is this because the argument for model= expects not a string but an object?


thanks, Mikkel

torsdag den 21. juni 2018 kl. 10.19.08 UTC+2 skrev Mikkel Kromann:
>
> I have a lot of models (say 30 or 40) which are so similar, that I have 
> handled them using slightly modified class based views.
>
> In urls.py:
> urlpatterns = [
> path('list//',ItemListView.as_view()),
> path('create//',  ItemCreateView.as_view()),
> path('update//',  ItemUpdateView.as_view()),
> path('delete//',  ItemDeleteView.as_view()),
> ]
>
> However, I'd really like to give all my urls names so that they can be 
> easily reversed (e.g. success links).
> urlpatterns = [
> path('list//',ItemListView.as_view(),  name
> =mName+'_list'),
> ]
>
> From what I can see, my model name mName is passed only to the view and 
> apparently not to the name constructor inside urls.py
> Also, while I do not entirely understand the reverse naming process, I 
> sense that it might not be too easy to reverse the url name if it is not 
> spelled out directly.
>
> Are there any options for handling this in urls.py?
> Or should I make a filter that will transform the model name and operation 
> name to an url and accept that I have to code url logic outside urls.py
> Or could I reprogram the path() function to make this possible?
> Or should I violate DRY and simply write 4 path lines for each of my 40 
> models?
>
>
> cheers + thanks, Mikkel
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e44a11ea-3115-4414-9af7-c1889c4f2f5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to construct reversible url names in urls.py using , regex etc

2018-06-21 Thread Melvyn Sopacua
On donderdag 21 juni 2018 10:19:08 CEST Mikkel Kromann wrote:

> However, I'd really like to give all my urls names so that they can be
> easily reversed (e.g. success links).
> urlpatterns = [
> path('list//',ItemListView.as_view(),  name=
> mName+'_list'),
> ]
> 
> From what I can see, my model name mName is passed only to the view and
> apparently not to the name constructor inside urls.py
> Also, while I do not entirely understand the reverse naming process, I
> sense that it might not be too easy to reverse the url name if it is not
> spelled out directly.
> 
> Are there any options for handling this in urls.py?

Take a look at crudlfap's Router class to see how to generate dynamic urls. In 
short: let a router who generates views for models generate the urlpatterns. 
All django is looking for is an iterable that is named 'urlpatterns' in a urls 
module.

https://github.com/yourlabs/crudlfap/blob/master/src/crudlfap/router.py#L274
-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7023284.eSgYguR0o7%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Is it possible to construct reversible url names in urls.py using , regex etc

2018-06-21 Thread Mikkel Kromann
I have a lot of models (say 30 or 40) which are so similar, that I have 
handled them using slightly modified class based views.

In urls.py:
urlpatterns = [
path('list//',ItemListView.as_view()),
path('create//',  ItemCreateView.as_view()),
path('update//',  ItemUpdateView.as_view()),
path('delete//',  ItemDeleteView.as_view()),
]

However, I'd really like to give all my urls names so that they can be 
easily reversed (e.g. success links).
urlpatterns = [
path('list//',ItemListView.as_view(),  name=
mName+'_list'),
]

>From what I can see, my model name mName is passed only to the view and 
apparently not to the name constructor inside urls.py
Also, while I do not entirely understand the reverse naming process, I 
sense that it might not be too easy to reverse the url name if it is not 
spelled out directly.

Are there any options for handling this in urls.py?
Or should I make a filter that will transform the model name and operation 
name to an url and accept that I have to code url logic outside urls.py
Or could I reprogram the path() function to make this possible?
Or should I violate DRY and simply write 4 path lines for each of my 40 
models?


cheers + thanks, Mikkel

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9cc50a2b-b613-4427-a8e4-101f9bf394d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Regex Validators doesn't validate while working in a shell

2016-09-12 Thread Daniel Roseman
On Monday, 12 September 2016 14:36:23 UTC+1, ashish...@finoit.co.in wrote:
>
> I've configured user's username field in following way
>
> username = models.CharField(
> _('username'),
> max_length=30,
> unique=True,
> help_text=_('Required. 30 characters or fewer. Letters, digits 
> and @/./+/-/_ only.'),
> validators=[
> validators.RegexValidator(
> r'^[\w.+-]+$',
> _('Enter a valid username. This value may contain only '
>   'letters, numbers ' 'and ./+/-/_ characters.')
> ),
> ],
> error_messages={
> 'unique': _("A user with that username already exists."),
> },
> )
>
> I'm getting error in admin panel but not in django-shell.
>
>
> Though django raises an error for maximum length in shell.
>
> Is it a bug? Or am I missing something.
>


This has nothing to do with being in the shell.

Validators aren't run on save, and that is the case everywhere, as noted 
explicitly in the validators 
documentation: 
https://docs.djangoproject.com/en/1.10/ref/validators/#how-validators-are-run
-- 
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9fa63938-11d8-40ca-b3b5-d531aa295c9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Regex Validators doesn't validate while working in a shell

2016-09-12 Thread ashish . goyal
I've configured user's username field in following way

username = models.CharField(
_('username'),
max_length=30,
unique=True,
help_text=_('Required. 30 characters or fewer. Letters, digits and 
@/./+/-/_ only.'),
validators=[
validators.RegexValidator(
r'^[\w.+-]+$',
_('Enter a valid username. This value may contain only '
  'letters, numbers ' 'and ./+/-/_ characters.')
),
],
error_messages={
'unique': _("A user with that username already exists."),
},
)

I'm getting error in admin panel but not in django-shell.








Though django raises an error for maximum length in shell.

Is it a bug? Or am I missing something.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3bbed56d-091d-492f-bac7-a3175df0e556%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


which regex are for filtering malicious input in django?

2016-06-09 Thread meInvent bbird
which regex are for filtering malicious input in django?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e1fe2b2f-e1d4-449d-bf94-3ba12fdf4b68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Don't understand regex-urls and DetailView...

2015-03-11 Thread inoyon artlover KLANGRAUSCH
I got it! :D (?P\w+) and NOT (P? .

Am Mittwoch, 11. März 2015 21:57:34 UTC+1 schrieb inoyon artlover 
KLANGRAUSCH:
>
> I don't understand why this doesn't work and smashes an 
>
> '*The current URL, lighter, didn't match any of these.'*
>
> my models.py
>
> class ShopList(models.Model):
> name = models.CharField(max_length=100, null=True, blank=True)
> description = models.CharField(max_length=100, null=True, blank=True)
> slug = models.SlugField(unique=True, null=True, blank=True)
>
> my views.py
>
> class ProductView(DetailView):
> model = models.ShopList
> template_name = "product.html"
>
> and finally urls.py
>
> url(r'^(P?\w+)$', views.ProductView.as_view()),
>
> Where is the mistake here
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/503d2d50-8c4d-4ca5-855a-31dfcbdbd038%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Don't understand regex-urls and DetailView...

2015-03-11 Thread inoyon artlover KLANGRAUSCH
I don't understand why this doesn't work and smashes an 

'*The current URL, lighter, didn't match any of these.'*

my models.py

class ShopList(models.Model):
name = models.CharField(max_length=100, null=True, blank=True)
description = models.CharField(max_length=100, null=True, blank=True)
slug = models.SlugField(unique=True, null=True, blank=True)

my views.py

class ProductView(DetailView):
model = models.ShopList
template_name = "product.html"

and finally urls.py

url(r'^(P?\w+)$', views.ProductView.as_view()),

Where is the mistake here

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/426f02f1-1176-43cb-a8da-52a90687f168%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Find duplicates with regex

2015-01-25 Thread Stephen J. Butler
The benefit to doing stuff like this in the database is that the
database can do it smarter than you can in Python. Is that true in
this case? I think not. If we were talking raw MySQL I'd suggest
running your Website column through something like REPLACE(Website,
'://www.', '') and then the count would work reasonably well.

But we're not talking raw MySQL. And if you want to use QuerySet I
assume you're still trying to stay database agnostic. That breaks it
down for me into two cases:

1. This is a query you'll be frequently and must run quickly. In that
case, I'd say to alter your model to include a normalized_website
field that is calculated from Website. Strip the 'www.' either in an
overridden save method or a pre_save signal. And don't use regexp for
this work; urlparse and urlunparse are much more appropriate (never
use a regexp to parse structured data when you can help it). Write a
data migration to handle the existing table. Then you can run your
query over normalized_website and things will work fine.

2. This is a query you'll run infrequently and doesn't need to run
quickly. In that case, just pull out all the records and do the
count/filter with Python code.

On Sun, Jan 25, 2015 at 10:58 PM,  <yakkades...@gmail.com> wrote:
> I posted this question to stackover flow but didn't get a good answer:
> http://stackoverflow.com/questions/28080545/django-find-duplicates-with-queryset-and-regex
>
> I want to find duplicates in db fields with a regex.
>
> I know I can use this to find duplicates:
> self.values('Website').annotate(count=Count('id')).order_by().filter(count__gt=1)
>
> I have a model like this:
> class company(models.Model):
>Website = models.URLField(blank=True, null=True )
>
> The problem is that www and non-www websites are marked as different
> websites.  I want some thing that will return duplicates where it realizes
> www and non-www are the same website.
>
> I know I can use a regex like this for www and non-www:
> Website__iregex='http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
>
> Here is an example:
> Company.objects.create(Website='http://example.com')
> Company.objects.create(Website='http://www.example.com')
> Company.objects.create(Website='http://example.org', Name='a')
> Company.objects.create(Website='http://example.org', Name='b')
>
> When I call:
> Company.objects.all().values('Website').annotate(count=Count('id')).order_by().filter(count__gt=1)
>
> It returns:
> 1.  http://example.org (from name=a) and http://example.org (from name=b)
>
> This is missing that example.com and www.example.com are the same website
> and duplicates.
>
> I want to use a regex so that I can tell django that example.com and
> www.example.com are the same websites.
>
> I want the return to be:
> 1.  http://example.org (from name=a) and http://example.org (from name=b)
> 2.  example.com www.example.com
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/452fad73-1319-4954-b004-7d0604705f30%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD4ANxVaKtLC%2BEBFRibMd%3D8M1nU56RQi0Brcoiy9Vs4ErTtNjg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Find duplicates with regex

2015-01-25 Thread yakkadesign
I posted this question to stackover flow but didn't get a good answer: 
http://stackoverflow.com/questions/28080545/django-find-duplicates-with-queryset-and-regex

I want to find duplicates in db fields with a regex. 

I know I can use this to find duplicates:
self.values('Website').annotate(count=Count('id')).order_by().filter(count__gt=1)

I have a model like this: 
class company(models.Model):
   Website = models.URLField(blank=True, null=True )

The problem is that www and non-www websites are marked as different 
websites.  I want some thing that will return duplicates where it realizes 
www and non-www are the same website.

I know I can use a regex like this for www and non-www:
Website__iregex='http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'

Here is an example:
Company.objects.create(Website='http://example.com')
Company.objects.create(Website='http://www.example.com')
Company.objects.create(Website='http://example.org', Name='a')
Company.objects.create(Website='http://example.org', Name='b')

When I call: 
Company.objects.all().values('Website').annotate(count=Count('id')).order_by().filter(count__gt=1)

It returns:
1.  http://example.org (from name=a) and http://example.org (from name=b)

This is missing that example.com and www.example.com are the same website 
and duplicates.

I want to use a regex so that I can tell django that example.com and 
www.example.com are the same websites.

I want the return to be:
1.  http://example.org (from name=a) and http://example.org (from name=b)
2.  example.com www.example.com


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/452fad73-1319-4954-b004-7d0604705f30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: there was this regex.........

2014-09-16 Thread MikeKJ

scrub this may bad found I was re-writing the error message to "" later on 
d'oh

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c4d93a3c-7d1b-474c-803d-fd26f0bfad32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


there was this regex.........

2014-09-16 Thread MikeKJ
pattern = 
re.compile(ur'^(?=\d{2}([\/])\d{2}\1\d{4}$)(?:0[1-9]|1\d|[2][0-8]|29(?!.02.(?!(?!(?:[02468][1-35-79]|[13579][0-13-57-9])00)\d{2}(?:[02468][048]|[13579][26])))|30(?!.02)|31(?=.(?:0[13578]|10|12))).(?:0[1-9]|1[012]).\d{4}$')
goodmatch = re.match(pattern, date_from)
#raise NameError(goodmatch)
if goodmatch:
pass
else:
date_from_error = "Incorrect input, must be dd/mm/yyy format"

goodmatch seems to always be None.

I tested the regex at regex101 abd it works with test data like 27/10/2015 

date_from is a date object so I also tried converting it to a string like

pattern = 
re.compile(ur'^(?=\d{2}([\/])\d{2}\1\d{4}$)(?:0[1-9]|1\d|[2][0-8]|29(?!.02.(?!(?!(?:[02468][1-35-79]|[13579][0-13-57-9])00)\d{2}(?:[02468][048]|[13579][26])))|30(?!.02)|31(?=.(?:0[13578]|10|12))).(?:0[1-9]|1[012]).\d{4}$')
str_date = str(date_from)
goodmatch = re.match(pattern, str_date)
if goodmatch:
pass
else:
date_from_error = "Incorrect input, must be dd/mm/yyy format"

Any help understanding and getting it to do the job defined in the if much 
appreciated

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ddf0232b-63e1-4d80-aea9-a03813f387ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: regex error?

2014-05-07 Thread Sergiy Khohlov
try this one
 url(r'/(?P\d+)$', DetailView.as_view(
model = Customer,
template_name="customer.html")),


Many thanks,

Serge


+380 636150445
skype: skhohlov

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADTRxJMX0sF6AUbtbtOAzaJcdjJ6WJGgL_RvoxdJnrufMKn3MA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: regex error?

2014-05-06 Thread G Z
ive also tried 

  url(r'^customers/([0-9])/$', DetailView.as_view(
model = Customer,
template_name="customer.html")),

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/623792ae-7ecd-4177-b2e1-ec502781c157%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


regex error?

2014-05-06 Thread G Z
Im using detailview to display customer individualy when the link is 
clicked on but its not recognizing the number i think my regex is wrong..


this is what i have 

from django.conf.urls import patterns, include, url
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from vmware.models import Customer

urlpatterns = patterns('',
url(r'^$', ListView.as_view(
queryset=Customer.objects.all().order_by("-id")[:100],
template_name="vms.html")),

url(r'^(?P\d+)$', DetailView.as_view(
model = Customer,
template_name="customer.html")),

)



This is what im getting


Page not found (404)
Request Method: GET
Request URL:http://pythondev.enki.co:8001/customers/2
Using the URLconf defined in provisioning.urls, Django tried these URL 
patterns, in this order:
^admin/
^customers ^$
^customers ^(?P\d+)$
^test/
The current URL, customers/2, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django 
settings file. Change that to False, and Django will display a standard 404 
page.


>From what I understand that means the regex isnt matching..

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ff13064e-6600-416f-8c3a-b8b7a6d117d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [newbie] -- Regex-matching ("Tango with Django")

2014-03-15 Thread Camilo Torres
On Friday, March 14, 2014 8:14:57 PM UTC-4:30, David wrote:
>
> I am wodering whether my implementation is incorrect or whether there is 
> a typo in the textbook. My question is how I can make sense of these 
> instructions: "The regular expression to match about/ is r'^about/'". 
>
> I was following the "Tango with Django" book. 
>
> In the exercises of chapter 3 I am asked to 
>
> """ 
> Now map the view ['about', which we just created] to /rango/about/. For 
> this step, you’ll only need to edit the urls.py of the rango application. 
> """ 
>
> Later, the author givessome hints, specifically: 
>
>
> """ 
> The regular expression to match about/ is r'^about/' 
> """ 
>
> Now, there was no way to do this. I finally managed to get 
>
> http://127.0.0.1:8000/rango/and 
> http://127.0.0.1:8000/rango/about/ 
>
> running satisfactorily (my code is below), but I was not even sure this 
> was intended. The author possibly wanted to create 
>
> http://127.0.0.1:8000/about/instead of 
> http://127.0.0.1:8000/rango/about/ 
>
> Thanks for clarifying this issue for me! 
>
> Cheers, 
>
> David 
>
>
>
>
> Here is my project/urls.py 
>
> from django.conf.urls import patterns, include, url 
>
> from django.contrib import admin 
> admin.autodiscover() 
>
> urlpatterns = patterns('', 
> # Examples: 
> # url(r'^$', 'justnow.views.home', name='home'), 
> # url(r'^blog/', include('blog.urls')), 
>
> # url(r'^admin/', include(admin.site.urls)), 
> url(r'^rango/', include('rango.urls')),  # ADD THIS NEW TUPLE! 
> url(r'^about/', include('rango.urls')),  # ADD THIS NEW TUPLE! 
> ) 
>
>
>
> The app urls.py: 
>
> from django.conf.urls import patterns, include, url 
> from rango import views 
>
> urlpatterns = patterns('', 
> url(r'^$', views.index, name='Rangos index'), 
> url(r'about', views.about, name='About page'), 
> ) 
>
> The app views.py: 
>
> from django.http import HttpResponse 
>
> def index(request): 
> return HttpResponse("Rango says hello.  href='/rango/about/'>About") 
>
> def about(request): 
> return HttpResponse("Here is the about page.  href='/rango/'>Index") 
>
>
>
>
>
>
>
> david@ubuntu:~/[...]/django_project$ tree 
> . 
> ├── manage.py 
> ├── notes.txt 
> ├── rango 
> │   ├── admin.py 
> │   ├── admin.pyc 
> │   ├── __init__.py 
> │   ├── __init__.pyc 
> │   ├── models.py 
> │   ├── models.pyc 
> │   ├── tests.py 
> │   ├── urls.py 
> │   ├── urls.pyc 
> │   ├── views.py 
> │   └── views.pyc 
> └── tango_with_django_project 
> ├── __init__.py 
> ├── __init__.pyc 
> ├── settings.py 
> ├── settings.pyc 
> ├── urls.py 
> ├── urls.pyc 
> ├── wsgi.py 
> └── wsgi.pyc 
>
Hello,

To point the about view to  http://127.0.0.1:8000/about/, in you 
project/urls.py, you should change:
url(r'^about/', include('rango.urls')),  # ADD THIS NEW TUPLE!
to
url(r'^about/',  rango.views.about, name='About page'),
(of course, you have to import rango.views)

With your current configuration, these two links:
http://127.0.0.1:8000/rango/and 
http://127.0.0.1:8000/rango/about/ 

points to the same as:
http://127.0.0.1:8000/about/ and 
http://127.0.0.1:8000/about/about/  

Because you included the same urls for 'rango/' and 'about/'

Yours,
Camilo

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/809b5684-ce25-469a-bb4b-13571bcc01f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [newbie] -- Regex-matching ("Tango with Django")

2014-03-14 Thread Shawn Milochik
You're meant to only have one include that redirects URLs beginning with
rango to the app's urls.py.

Then, the app's urls.py must not have /rango in the URLs. The idea is that
all URLs starting with "rango" get the "rango" stripped off and passed to
the rango app, which itself has / and /about.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOzwKwEkFqGBaxQQ76oce1zdKQDDWD8MnBdhKjzvrWegOJYoWQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[newbie] -- Regex-matching ("Tango with Django")

2014-03-14 Thread David
Dear list,

I am wodering whether my implementation is incorrect or whether there is
a typo in the textbook. My question is how I can make sense of these
instructions: "The regular expression to match about/ is r'^about/'".

I was following the "Tango with Django" book.

In the exercises of chapter 3 I am asked to

"""
Now map the view ['about', which we just created] to /rango/about/. For
this step, you’ll only need to edit the urls.py of the rango application.
"""

Later, the author gives some hints, specifically:


"""
The regular expression to match about/ is r'^about/'
"""

Now, there was no way to do this. I finally managed to get

http://127.0.0.1:8000/rango/and
http://127.0.0.1:8000/rango/about/

running satisfactorily (my code is below), but I was not even sure this
was intended. The author possibly wanted to create

http://127.0.0.1:8000/about/instead of
http://127.0.0.1:8000/rango/about/

Thanks for clarifying this issue for me!

Cheers,

David




Here is my project/urls.py

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'justnow.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),

# url(r'^admin/', include(admin.site.urls)),
url(r'^rango/', include('rango.urls')),  # ADD THIS NEW TUPLE!
url(r'^about/', include('rango.urls')),  # ADD THIS NEW TUPLE!
)



The app urls.py:

from django.conf.urls import patterns, include, url
from rango import views

urlpatterns = patterns('',
url(r'^$', views.index, name='Rangos index'),
url(r'about', views.about, name='About page'),
)

The app views.py:

from django.http import HttpResponse

def index(request):
return HttpResponse("Rango says hello. About")

def about(request):
return HttpResponse("Here is the about page. Index")







david@ubuntu:~/[...]/django_project$ tree
.
├── manage.py
├── notes.txt
├── rango
│   ├── admin.py
│   ├── admin.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── tests.py
│   ├── urls.py
│   ├── urls.pyc
│   ├── views.py
│   └── views.pyc
└── tango_with_django_project
├── __init__.py
├── __init__.pyc
├── settings.py
├── settings.pyc
├── urls.py
├── urls.pyc
├── wsgi.py
└── wsgi.pyc

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5323A289.9000503%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Re: url tag: "'str' object has no attribute 'regex'"

2013-05-15 Thread quilpy
thanks, that helped

On Tuesday, 2 April 2013 08:45:32 UTC+5:30, Wenliang Chen wrote:
>
> Hi,
>
> I got the same issue.  And I solved it doing this:
>
> urlpatterns= patterns('',
> (r'^login/$', 'django.contrib.auth.views.login'),   <-Remove the 
> last comma in the patterns()
> )
>
> Hope this helps
>
> On Friday, May 18, 2012 5:58:28 AM UTC+8, refreegrata wrote:
>>
>> Hello list
>>
>> I know, this question has been posted and resolved before, but the 
>> solutions don't work in my situation. I don't know why.
>>
>> When I try to use the "url" tag in any template an exception is raised:
>> "'str' object has no attribute 'regex'"
>>
>> for example, with this I got the error:
>> 
>> urls.py (main)
>> -
>> from django.conf.urls import patterns, include, url
>>
>> urlpatterns= patterns('',
>> (r'^registration/', include('apps.registration.urls')),
>> (r'', 'django.contrib.auth.views.login'),
>> )
>> -
>>
>> urls.py (registration)
>> -
>> from django.conf.urls import patterns, include, url
>>
>> urlpatterns= patterns('',
>> (r'^login/$', 'django.contrib.auth.views.login'),
>> )
>> -
>>
>> login.html (in templates/registration)
>> -
>> {{ form }}
>> {% url "django.contrib.auth.views.login" %} <---here is the problem. It's 
>> just an stupid test for the problem
>> -
>>
>> Fail with:
>>  - {% url django.contrib.auth.views.login %}
>>  - {% url 'django.contrib.auth.views.login' %}
>>  - {% url "django.contrib.auth.views.login" %}
>>
>> I add this at the end of the file "settings.py":
>> --
>> import django.template
>> django.template.add_to_builtins('django.templatetags.future')
>> --
>> Including or excluding the last lines doesn't matter. The problem appear 
>> in the both cases.
>>
>> I'm using Django 1.4, and Python 2.6 over Centos 6.2. Maybe I must to 
>> include something else in the settings?
>>
>> Thanks for read and sorry for my bad english.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: url tag: "'str' object has no attribute 'regex'"

2013-04-01 Thread Wenliang Chen
Hi,

I got the same issue.  And I solved it doing this:

urlpatterns= patterns('',
(r'^login/$', 'django.contrib.auth.views.login'),   <-Remove the 
last comma in the patterns()
)

Hope this helps

On Friday, May 18, 2012 5:58:28 AM UTC+8, refreegrata wrote:
>
> Hello list
>
> I know, this question has been posted and resolved before, but the 
> solutions don't work in my situation. I don't know why.
>
> When I try to use the "url" tag in any template an exception is raised:
> "'str' object has no attribute 'regex'"
>
> for example, with this I got the error:
> 
> urls.py (main)
> -
> from django.conf.urls import patterns, include, url
>
> urlpatterns= patterns('',
> (r'^registration/', include('apps.registration.urls')),
> (r'', 'django.contrib.auth.views.login'),
> )
> -
>
> urls.py (registration)
> -
> from django.conf.urls import patterns, include, url
>
> urlpatterns= patterns('',
> (r'^login/$', 'django.contrib.auth.views.login'),
> )
> -
>
> login.html (in templates/registration)
> -
> {{ form }}
> {% url "django.contrib.auth.views.login" %} <---here is the problem. It's 
> just an stupid test for the problem
> -
>
> Fail with:
>  - {% url django.contrib.auth.views.login %}
>  - {% url 'django.contrib.auth.views.login' %}
>  - {% url "django.contrib.auth.views.login" %}
>
> I add this at the end of the file "settings.py":
> --
> import django.template
> django.template.add_to_builtins('django.templatetags.future')
> --
> Including or excluding the last lines doesn't matter. The problem appear 
> in the both cases.
>
> I'm using Django 1.4, and Python 2.6 over Centos 6.2. Maybe I must to 
> include something else in the settings?
>
> Thanks for read and sorry for my bad english.
>
>
>
>
>
>
>
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




RE: regex

2013-01-25 Thread Babatunde Akinyanmi
'.' matches any character except a new line

Sent from my Windows Phone
--
From: arm
Sent: 1/25/2013 10:09 AM
To: django-users@googlegroups.com
Subject: regex

Hi,

I'm trying to figure out the regular expressions that will match any number
and punctuation and chars like +,#,§ etc . Any advice?




 --
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.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: regex

2013-01-25 Thread Larry Martell
On Fri, Jan 25, 2013 at 2:09 AM, arm  wrote:
>
> Hi,
>
> I'm trying to figure out the regular expressions that will match any
> number and punctuation and chars like +,#,§ etc . Any advice?


http://www.regular-expressions.info/charclass.html

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




regex

2013-01-25 Thread arm
Hi,

I'm trying to figure out the regular expressions that will match any number 
and punctuation and chars like +,#,§ etc . Any advice?




-- 
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.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: only utf-8 letters regex pattern

2013-01-16 Thread Adam Mesha
You can explicitly add the Turkish characters to the character class if
there are just a few of them. You could also use the UNICODE regex flag and
do something like ur'(?u)^[^\W\d_]+$', which will match any string
consisting solely of alphabetic unicode characters.

2013/1/16 armagan <armagan.er...@gmail.com>

> Hi,
>
> I'm trying to use regex patterns in django form. I successed in only
> letters regex pattern. But form controler declines Turkish chars. I think I
> must use utf-8 regex. Can you help me?
>
> name = forms.RegexField(regex =r'^[a-zA-Z]+$')
>
> Thanks for help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/n_RDevJyBMgJ.
> 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.
>



-- 
Adam Mesha <adam.rai...@gmail.com>
Life is either a daring adventure, or nothing. - Helen Keller

-- 
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: only utf-8 letters regex pattern

2013-01-16 Thread Jian Chang
you can use unicode.

2013/1/16 armagan 

> Turkish chars

-- 
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.



only utf-8 letters regex pattern

2013-01-16 Thread armagan
Hi,

I'm trying to use regex patterns in django form. I successed in only 
letters regex pattern. But form controler declines Turkish chars. I think I 
must use utf-8 regex. Can you help me?

name = forms.RegexField(regex =r'^[a-zA-Z]+$')

Thanks for help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/n_RDevJyBMgJ.
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 “break” from a regex in urlconf

2012-08-27 Thread Matthew Meyer
Fantastic solution, thank you so much. I will be sure to loose those 
phrases from my vocab as well :)

On Monday, August 27, 2012 3:18:52 AM UTC-4, Melvyn Sopacua wrote:
>
> On 27-8-2012 4:14, Matthew Meyer wrote: 
>
> > So the question: Is there a way I can keep the flexible tag regex 
> redirect 
> > behavior but then "break" from it once I reach a product page? One 
> > important thing to note is that I want to keep the product page within 
> the 
> > built up url scheme like: mens/shirts/buttonups/shirt-product/ 
>
> The first thing to note is that you need to get "redirect" and "break 
> out" out of your vocabulary. While Django's urlconfs look and walk like 
> rewrite engines, they are not rewrite engines. The primary difference is 
> that matches are handled in order and the first match wins, so there is 
> no "break out" principle. 
> Since a slug and a tag in your matches consist of identical character 
> classes there is no way to differentiate between one or the other. The 
> easy solution and one that is in line with the semantics of URLs is to 
> drop the trailing slash for the product. 
> "Back in the day" trailing slashes meant "directory listings" and no 
> trailing slash referred to "document requests" and this applies to your 
> scheme also. So your product url becomes: 
> url(r'^(?P.+)/(?P[-\w]+)$', 'product_page'), 
> -- 
> Melvyn Sopacua 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/FiWEJMZ7PHoJ.
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 “break” from a regex in urlconf

2012-08-27 Thread Melvyn Sopacua
On 27-8-2012 4:14, Matthew Meyer wrote:

> So the question: Is there a way I can keep the flexible tag regex redirect 
> behavior but then "break" from it once I reach a product page? One 
> important thing to note is that I want to keep the product page within the 
> built up url scheme like: mens/shirts/buttonups/shirt-product/

The first thing to note is that you need to get "redirect" and "break
out" out of your vocabulary. While Django's urlconfs look and walk like
rewrite engines, they are not rewrite engines. The primary difference is
that matches are handled in order and the first match wins, so there is
no "break out" principle.
Since a slug and a tag in your matches consist of identical character
classes there is no way to differentiate between one or the other. The
easy solution and one that is in line with the semantics of URLs is to
drop the trailing slash for the product.
"Back in the day" trailing slashes meant "directory listings" and no
trailing slash referred to "document requests" and this applies to your
scheme also. So your product url becomes:
url(r'^(?P.+)/(?P[-\w]+)$', 'product_page'),
-- 
Melvyn Sopacua

-- 
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.



how to “break” from a regex in urlconf

2012-08-26 Thread Matthew Meyer


I have the following views:

def tag_page(request, tag):

products = Product.objects.filter(tag=tag)

return render(request, 'shop/tag_page.html', {'products': products, 'tag': 
tag})


def product_page(request, slug):

product = Product.objects.get(slug=slug)

return render(request, 'shop/product_page.html', {'product': product})

along with the following url configurations:

url(r'^(?P.+)/$', 'tag_page'),
url(r'^(?P.+)/(?P[-\w]+)/$', 'product_page'),

The regex that has "tag" in it allows a url path to grow arbitrarily while 
sort of circularly redirecting to the tag_page view.

This lets me have the url: /mens/shirts/buttonups/, where all sections 
(/mens, /mens/shirts, /mens/shirts/buttonups/) of the path direct to the 
tag_page view, which is desired.

I want to end this behavior at some point however, and direct to a 
product_page view, which I attempt to accomplish with:

url(r'^(?P.+)/(?P[-\w]+)/$', 'product_page'),

When I follow a product_page link:

{{ product }}

I am directed to the tag_pag view. Presumably because that slug url matches 
the tag regex.

So the question: Is there a way I can keep the flexible tag regex redirect 
behavior but then "break" from it once I reach a product page? One 
important thing to note is that I want to keep the product page within the 
built up url scheme like: mens/shirts/buttonups/shirt-product/

Any insight is appreciated, Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/EdbHp4taon0J.
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: Url regex keeps django busy/crashing

2012-08-02 Thread Melvyn Sopacua
On 3-8-2012 2:34, Melvyn Sopacua wrote:

Correction:
> url(r'^(?P\w[\w-]+-/$', 'detail')
insert question mark here -->  ?

-- 
Melvyn Sopacua

-- 
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: Url regex keeps django busy/crashing

2012-08-02 Thread Melvyn Sopacua
On 26-7-2012 16:45, Joe wrote:
> Hey, I have a url regex like this which is keeping django extremely busy 
> (20secs to 1min to handle a request). On some urls it even crashes.
> 
> my regex:
> 
> url(r'^(?P(\w+-?)*)/$', 'detail'),

Turn the * into a + and you'll see great improvements and I also think
you don't want to match '//' as a valid URL part.
Also, I think this example will satisfy your requirements in practice:

url(r'^(?P\w[\w-]+-/$', 'detail')

The only difference is that dashes are allowed to follow each other. I
can only think of one valid reason to not use the above URL and that is
if "multiple dashes" are captured in another URL.
Remember that URL patterns are not your validators. It's nice if you can
prevent a view from being called by carefully constructing your URL
patterns, but if parsing the regex takes longer then calling the view
you loose performance instead.
Also, validating if a URL contains two or more consecutive dashes is
easily done in a view and does not even need regular expressions:
def detail(request, item_url) :
if '--' in item_url :
raise 404

Even more improvements if you keep the urls lower case (or uppercase,
but not mixed case) and use [a-z0-9_] instead of \w.
-- 
Melvyn Sopacua

-- 
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: Url regex keeps django busy/crashing

2012-07-28 Thread Tim Chase
On 07/26/12 09:45, Joe wrote:
> url(r'^(?P(\w+-?)*)/$', 'detail'),
> 
> replaced with:
> 
> url(r'^(?P[\w-]+)/$', 'detail'),

Russell gave you good background on the why (including that Django
was stung by the same issue).  It would help if you more clearly
defined what you wanted to target.  Your first one can match things like

  x-x-x-x-

with trailing dashes, and your second one can match things like

  --  # pure dashes
  ---xxx  # leading dashes
  --xx--  # leading and trailing dashes

I suspect you want an expression something like

  (?P\w+(?:-\w+)*)/$

perhaps having a "?" after the terminal slash to make it optional.
This expression is roughly "one or more \words separated by one
dash."  You might change "\w" to "[a-zA-Z]" to ensure you can't
match odd things like

  _-_-_-_

("\w" includes underscores).

-tkc



-- 
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: Url regex keeps django busy/crashing

2012-07-27 Thread Russell Keith-Magee
On Thu, Jul 26, 2012 at 10:45 PM, Joe <ad...@gamebee.de> wrote:
> Hey, I have a url regex like this which is keeping django extremely busy
> (20secs to 1min to handle a request). On some urls it even crashes.
>
> my regex:
>
> url(r'^(?P(\w+-?)*)/$', 'detail'),
>
>
> view:
>
> def detail(request, item_url):
>i = get_object_or_404(Page, url=item_url,published=True)
>return render_to_response('item/detail.html', {'item':i},
>context_instance=RequestContext(request))
>
> replaced with:
>
> url(r'^(?P[\w-]+)/$', 'detail'),
>
>
> The replacement works like a charm. What is wrong with the first regex?

Hi Joe,

There's nothing strictly *wrong* with the first regex -- it's just
describes a very complex lookup strategy, and as a result, it takes
extra time to compute it.

In the second regex, you're asking for "a string of 1 or more
characters that are either word-like or '-'". That's a very easy thing
to check - if you think of how you would manually implement code that
check that policy, it could be done with a simple if inside a while
loop; as soon as you find a character that doesn't match, you can bail
out.

However, the first regex is asking for "0 or more groups of word like
characters, each of which might be followed by a '-'". Consider a
trivial case, matching against the string abcde. It can match the
first regex in an incredible number of ways:

(a)(b)(c)(d)(e)
(ab)(c)(d)(e)
(abc)(d)(e)
(abcd)(e)
(abcde)
(a)(bc)(d)(e)
(a)(bcd)(e)
(a)(bcde)
(a)(b)(cde)
…
and so on. Because you're asking the regex to preserve groups, the
algorithm needs to essentially work out every single one of these
groups, and then determine which set will be reported as the actual
match. As you can guess, this can take some time, which you're
observing as a 1 minute delay in serving a URL.

This is one of the gotchas that comes from using regular expressions.
They're a very powerful language for expressing constraints, but you
need to be careful that you don't accidentally fall into a trap where
you're asking for something very complex.

And don't worry - you're in good company being bitten by this problem.
There was a Django security release caused *specifically* by a regular
expression like yours. Django uses regular expressions to validate
URLs and email form inputs, and at one point, the regex that was used
to validate email addresses was constructed in such a way that it was
possible to provide a very simple string that would cause the
validator to take 30 seconds to confirm that it wasn't valid. Write a
tool that hits the same URL and validates the same string 100 times,
and you've got yourself a DDOS attack.

So - when you're building your URL patterns, you should be trying to
keep your regular expressions as simple as possible -- i.e., simple
linear probes. If you really do need to match a complex pattern, you'd
be better served using a simple regex in the URL pattern, and then
doing more specific validation in the view (and raising 404 if the
pattern doesn't match what you need it to).

Yours,
Russ Magee %-)

-- 
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.



Url regex keeps django busy/crashing

2012-07-26 Thread Joe
Hey, I have a url regex like this which is keeping django extremely busy 
(20secs to 1min to handle a request). On some urls it even crashes.

my regex:

url(r'^(?P(\w+-?)*)/$', 'detail'),


view:

def detail(request, item_url):
   i = get_object_or_404(Page, url=item_url,published=True)
   return render_to_response('item/detail.html', {'item':i},
   context_instance=RequestContext(request))

replaced with:

url(r'^(?P[\w-]+)/$', 'detail'),


The replacement works like a charm. What is wrong with the first regex?

Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/lVIrewdZipMJ.
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: replace or regex

2012-06-28 Thread Tim Chase
On 06/28/12 01:42, pakyazilim wrote:
> i have text ;
> **
>A
>  
>  B
>  
>   
> **
> *
> *
> *i want to remove first  end for text end  tag. *
> *how can i it?*

Depends on what you want to happen in various odd edge-cases:

- what happens if other tags surround the outside  block like

   Ab

- what happens if there's only an opening or closing  tag but
not the other?

- what happens if the  tag has attributes on it like

  ...

- what happens if case differs?

  ...

- what happens if there are superfluous spaces?

  < ul > ... < / ul >

- do you want to remove the tags and keep the whitespace around
them, or do you want to condense the whitespace too?


You likely want either a regexp or two, or you want a full-blown
HTML parser.

-tkc


-- 
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: replace or regex

2012-06-28 Thread Kurtis Mullins
You could use regular expressions to parse the string, break it up
into chunks and simply remove the first and last chunk (or whatever
you're looking for)
Also, you could use a DOM Parser to parse this tree and remove the
outer-most . Just make sure you don't remove the entire DOM Tree
within the UL.
I'd google around for ways to do either.

-- 
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: replace or regex

2012-06-28 Thread Abdulkerim KELEŞ
first is s='**
   A
 
 B
 
  
**'
s.replace('' ,' ', 1 )

but i dont remove last  tag.

2012/6/28 pakyazilim 

> i have text ;
> **
>A
>  
>  B
>  
>   
> **
> *
> *
> *i want to remove first  end for text end  tag. *
> *how can i it?*
> *thanks you...*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/lPA-eOEgEBYJ.
> 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.



replace or regex

2012-06-28 Thread pakyazilim
i have text ;
**
   A
 
 B
 
  
**
*
*
*i want to remove first  end for text end  tag. *
*how can i it?*
*thanks you...*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/lPA-eOEgEBYJ.
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.



url tag: "'str' object has no attribute 'regex'"

2012-05-17 Thread refreegrata
Hello list

I know, this question has been posted and resolved before, but the 
solutions don't work in my situation. I don't know why.

When I try to use the "url" tag in any template an exception is raised:
"'str' object has no attribute 'regex'"

for example, with this I got the error:

urls.py (main)
-
from django.conf.urls import patterns, include, url

urlpatterns= patterns('',
(r'^registration/', include('apps.registration.urls')),
(r'', 'django.contrib.auth.views.login'),
)
-

urls.py (registration)
-
from django.conf.urls import patterns, include, url

urlpatterns= patterns('',
(r'^login/$', 'django.contrib.auth.views.login'),
)
-

login.html (in templates/registration)
-
{{ form }}
{% url "django.contrib.auth.views.login" %} <---here is the problem. It's 
just an stupid test for the problem
-

Fail with:
 - {% url django.contrib.auth.views.login %}
 - {% url 'django.contrib.auth.views.login' %}
 - {% url "django.contrib.auth.views.login" %}

I add this at the end of the file "settings.py":
--
import django.template
django.template.add_to_builtins('django.templatetags.future')
--
Including or excluding the last lines doesn't matter. The problem appear in 
the both cases.

I'm using Django 1.4, and Python 2.6 over Centos 6.2. Maybe I must to 
include something else in the settings?

Thanks for read and sorry for my bad english.












-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/JoW317aiojgJ.
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: URL regex not matching

2012-04-24 Thread Swaroop Shankar V
I changed to your regex and it works fine. Thanks a lot :)

Thanks and Regards,
Swaroop Shankar V



On Sun, Apr 22, 2012 at 2:37 PM, yati sagade <yati.sag...@gmail.com> wrote:

> I think that one also matches upto one whitespace character(space, tab or
> newline) within the username(The \s).
>
>
> On Sun, Apr 22, 2012 at 2:12 PM, Swaroop Shankar V <swaroo...@gmail.com>wrote:
>
>> Thanks a lot for your reply. I just found an regex from some blog which
>> is as follows
>>
>> (r'^user/([\w\'\.\-]+\s?[\w\'\.\-]+)/$','accounts.views.userProfile'),
>>
>> and this seems to be working fine. Have not tested all the use cases for
>> this regex, but anyway username with . (dot) is working fine now.
>>
>> Swaroop Shankar V
>>
>>
>>
>>
>> On Sun, Apr 22, 2012 at 2:02 PM, yati sagade <yati.sag...@gmail.com>wrote:
>>
>>> I'm not sure, but I think this should work - try it out and let us know.
>>>
>>> r'^user/([\w\-+.@]+)/$'
>>>
>>> I'm not too good with regexes, either. No one is. Also, characters like
>>> "+" are encoded in URLs - so you might want to think of that.
>>>
>>>
>>> On Sun, Apr 22, 2012 at 1:42 PM, Swaroop Shankar V 
>>> <swaroo...@gmail.com>wrote:
>>>
>>>> Hello All,
>>>> I need some urgent help with this one. Am trying to show a user profile
>>>> when the user navigates to a url of this format
>>>>
>>>> http://example.com/user/
>>>>
>>>> I have provided the following expression in my urls.py file
>>>>
>>>> (r'^user/(\w+)/$','accounts.views.userProfile'),
>>>>
>>>> this working fine for normal usernames, but if the user add a . (dot)
>>>> in between his username the url do not match with the regex and throws Page
>>>> not found error.
>>>>
>>>> Since the django username supports  Letters, digits and @/./+/-/_  i
>>>> want all these to be supported in my url. Could someone please help me to
>>>> construct the url. Am pretty weak in regex and it will take me sometime to
>>>> build a proper regex for the above url. Thanks
>>>>
>>>> Regards,
>>>>
>>>> Swaroop Shankar V
>>>>
>>>>  --
>>>> 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.
>>>>
>>>
>>>
>>>
>>> --
>>> Yati Sagade <http://twitter.com/yati_itay>
>>>
>>> Twitter: @yati_itay <http://twitter.com/yati_itay>
>>>
>>> Organizing member of TEDx EasternMetropolitanBypass
>>> http://www.ted.com/tedx/events/4933
>>>
>>> https://www.facebook.com/pages/TEDx-EasternMetropolitanBypass/337763226244869
>>>
>>>
>>>  --
>>> 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.
>>
>
>
>
> --
> Yati Sagade <http://twitter.com/yati_itay>
>
> Twitter: @yati_itay <http://twitter.com/yati_itay>
>
> Organizing member of TEDx EasternMetropolitanBypass
> http://www.ted.com/tedx/events/4933
>
> https://www.facebook.com/pages/TEDx-EasternMetropolitanBypass/337763226244869
>
>
>  --
> 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: URL regex not matching

2012-04-22 Thread yati sagade
I think that one also matches upto one whitespace character(space, tab or
newline) within the username(The \s).

On Sun, Apr 22, 2012 at 2:12 PM, Swaroop Shankar V <swaroo...@gmail.com>wrote:

> Thanks a lot for your reply. I just found an regex from some blog which is
> as follows
>
> (r'^user/([\w\'\.\-]+\s?[\w\'\.\-]+)/$','accounts.views.userProfile'),
>
> and this seems to be working fine. Have not tested all the use cases for
> this regex, but anyway username with . (dot) is working fine now.
>
> Swaroop Shankar V
>
>
>
>
> On Sun, Apr 22, 2012 at 2:02 PM, yati sagade <yati.sag...@gmail.com>wrote:
>
>> I'm not sure, but I think this should work - try it out and let us know.
>>
>> r'^user/([\w\-+.@]+)/$'
>>
>> I'm not too good with regexes, either. No one is. Also, characters like
>> "+" are encoded in URLs - so you might want to think of that.
>>
>>
>> On Sun, Apr 22, 2012 at 1:42 PM, Swaroop Shankar V 
>> <swaroo...@gmail.com>wrote:
>>
>>> Hello All,
>>> I need some urgent help with this one. Am trying to show a user profile
>>> when the user navigates to a url of this format
>>>
>>> http://example.com/user/
>>>
>>> I have provided the following expression in my urls.py file
>>>
>>> (r'^user/(\w+)/$','accounts.views.userProfile'),
>>>
>>> this working fine for normal usernames, but if the user add a . (dot) in
>>> between his username the url do not match with the regex and throws Page
>>> not found error.
>>>
>>> Since the django username supports  Letters, digits and @/./+/-/_  i
>>> want all these to be supported in my url. Could someone please help me to
>>> construct the url. Am pretty weak in regex and it will take me sometime to
>>> build a proper regex for the above url. Thanks
>>>
>>> Regards,
>>>
>>> Swaroop Shankar V
>>>
>>>  --
>>> 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.
>>>
>>
>>
>>
>> --
>> Yati Sagade <http://twitter.com/yati_itay>
>>
>> Twitter: @yati_itay <http://twitter.com/yati_itay>
>>
>> Organizing member of TEDx EasternMetropolitanBypass
>> http://www.ted.com/tedx/events/4933
>>
>> https://www.facebook.com/pages/TEDx-EasternMetropolitanBypass/337763226244869
>>
>>
>>  --
>> 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.
>



-- 
Yati Sagade <http://twitter.com/yati_itay>

Twitter: @yati_itay <http://twitter.com/yati_itay>

Organizing member of TEDx EasternMetropolitanBypass
http://www.ted.com/tedx/events/4933
https://www.facebook.com/pages/TEDx-EasternMetropolitanBypass/337763226244869

-- 
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: URL regex not matching

2012-04-22 Thread Swaroop Shankar V
Thanks a lot for your reply. I just found an regex from some blog which is
as follows

(r'^user/([\w\'\.\-]+\s?[\w\'\.\-]+)/$','accounts.views.userProfile'),

and this seems to be working fine. Have not tested all the use cases for
this regex, but anyway username with . (dot) is working fine now.

Swaroop Shankar V



On Sun, Apr 22, 2012 at 2:02 PM, yati sagade <yati.sag...@gmail.com> wrote:

> I'm not sure, but I think this should work - try it out and let us know.
>
> r'^user/([\w\-+.@]+)/$'
>
> I'm not too good with regexes, either. No one is. Also, characters like
> "+" are encoded in URLs - so you might want to think of that.
>
>
> On Sun, Apr 22, 2012 at 1:42 PM, Swaroop Shankar V <swaroo...@gmail.com>wrote:
>
>> Hello All,
>> I need some urgent help with this one. Am trying to show a user profile
>> when the user navigates to a url of this format
>>
>> http://example.com/user/
>>
>> I have provided the following expression in my urls.py file
>>
>> (r'^user/(\w+)/$','accounts.views.userProfile'),
>>
>> this working fine for normal usernames, but if the user add a . (dot) in
>> between his username the url do not match with the regex and throws Page
>> not found error.
>>
>> Since the django username supports  Letters, digits and @/./+/-/_  i
>> want all these to be supported in my url. Could someone please help me to
>> construct the url. Am pretty weak in regex and it will take me sometime to
>> build a proper regex for the above url. Thanks
>>
>> Regards,
>>
>> Swaroop Shankar V
>>
>>  --
>> 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.
>>
>
>
>
> --
> Yati Sagade <http://twitter.com/yati_itay>
>
> Twitter: @yati_itay <http://twitter.com/yati_itay>
>
> Organizing member of TEDx EasternMetropolitanBypass
> http://www.ted.com/tedx/events/4933
>
> https://www.facebook.com/pages/TEDx-EasternMetropolitanBypass/337763226244869
>
>
>  --
> 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: URL regex not matching

2012-04-22 Thread yati sagade
I'm not sure, but I think this should work - try it out and let us know.

r'^user/([\w\-+.@]+)/$'

I'm not too good with regexes, either. No one is. Also, characters like "+"
are encoded in URLs - so you might want to think of that.


On Sun, Apr 22, 2012 at 1:42 PM, Swaroop Shankar V <swaroo...@gmail.com>wrote:

> Hello All,
> I need some urgent help with this one. Am trying to show a user profile
> when the user navigates to a url of this format
>
> http://example.com/user/
>
> I have provided the following expression in my urls.py file
>
> (r'^user/(\w+)/$','accounts.views.userProfile'),
>
> this working fine for normal usernames, but if the user add a . (dot) in
> between his username the url do not match with the regex and throws Page
> not found error.
>
> Since the django username supports  Letters, digits and @/./+/-/_  i want
> all these to be supported in my url. Could someone please help me to
> construct the url. Am pretty weak in regex and it will take me sometime to
> build a proper regex for the above url. Thanks
>
> Regards,
>
> Swaroop Shankar V
>
>  --
> 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.
>



-- 
Yati Sagade <http://twitter.com/yati_itay>

Twitter: @yati_itay <http://twitter.com/yati_itay>

Organizing member of TEDx EasternMetropolitanBypass
http://www.ted.com/tedx/events/4933
https://www.facebook.com/pages/TEDx-EasternMetropolitanBypass/337763226244869

-- 
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.



URL regex not matching

2012-04-22 Thread Swaroop Shankar V
Hello All,
I need some urgent help with this one. Am trying to show a user profile
when the user navigates to a url of this format

http://example.com/user/

I have provided the following expression in my urls.py file

(r'^user/(\w+)/$','accounts.views.userProfile'),

this working fine for normal usernames, but if the user add a . (dot) in
between his username the url do not match with the regex and throws Page
not found error.

Since the django username supports  Letters, digits and @/./+/-/_  i want
all these to be supported in my url. Could someone please help me to
construct the url. Am pretty weak in regex and it will take me sometime to
build a proper regex for the above url. Thanks

Regards,

Swaroop Shankar V

-- 
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.



python, django, regex, θæŋkfəli

2011-11-21 Thread gintare
This is corrected question. The first time it was submitted on
2011.11.22 nd.

I am not able to save string with special characters, such as θæŋ
after re.search(string).
#saving to the model Textfield does not work. Instead of θæŋkfəli, i
am getting shown "\xce\xb8\xc3\xa6\xc5\x8bkf\xc9\x99li" in Admin page.
Is it error in re.search?
Should i use special parameters during model field saving or in Admin
entry displaying?

[code]
lines='title="Listen to audio" />/ˈθæŋkfəli/ adverb' #the
string which i wan to save exactly as it is, Django saves it correctly

liness=smart_str(lines, encoding='utf-8', strings_only=False,
errors='replace') # saves correctly, i mean in Admin page in Textfield
i can read "θæŋ" characters
linesu=smart_unicode(lines, encoding='utf-8', strings_only=False,
errors='replace')  # saves correctly[/code]

## ***AFTER TRYING TO SEARCH part of unicode string linesu for
θæŋkfəli Django does not save it in needed special characters.
Instead of θæŋkfəli, i am getting "\xce\xb8\xc3\xa6\xc5\x8bkf
\xc9\x99li"  or "\u03b8\xe6\u014bkf\u0259li", Below there are shown 3
trials to get correct text and also described error in searching
liness= bytes string***

[code]stryc=re.compile('\s*/\s*(?P. .*)', re.DOTALL)
#\s+/\s+\s+[\\a-zA-Z0-9\s]
+/\s+ '
strys=re.search(stryc, linesu)[/code]

1)
[code]Pronun=stryWordcs.groups('Pronun')
a=Pronunciation(field=Pronun)
a.save()
# Pronun=  "θæŋkfəli"  [/code]

#saving to the model Textfield does not work. Instead of θæŋkfəli, i
am getting  "\u03b8\xe6\u014bkf\u0259li"

2)
[code]Pronun=stryWordcs.groups('Pronun')
Pronun=smart_str(Pronun, encoding='utf-8', strings_only=False,
errors='replace')
a=Pronunciation(field=Pronun)
a.save()[/code]

#saving to the model Textfield does not work. Instead of θæŋkfəli, i
am getting \xce\xb8\xc3\xa6\xc5\x8bkf\xc9\x99li"

3)
[code]Pronun=stryWordcs.groups('Pronun')
Pronun=Pronun.encode()
a=Pronunciation(field=Pronun)
a.save() [/code]
#saving to the model Textfield does not work. Instead of θæŋkfəli, i
am getting \xce\xb8\xc3\xa6\xc5\x8bkf\xc9\x99li"

## ***
# 4) if i try to search in lines or liness i am not able to find
θæŋkfəli due coding error about special character  ˈ (small stick on
top =\xcb\x88 = \u02c8) . Thus i make search on unicode string.

-- 
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: Storing regex raw string literal in Django model?

2011-10-14 Thread Daniel Roseman
On Thursday, 13 October 2011 23:58:00 UTC+1, Victor Hooi wrote:
>
> Hi,
>
> I have Django model and in one of the fields I need to store a regex string 
> that I can later use.
>
> class Foo(models.Model):
> name = models.CharField(max_length=30, unique=True)
> regex_string = models.TextField()
>
>
> So for example, the regex_string field might be set to:
>
> r'\d{2}'
>
>
> I then try to retrieve this later, compile it as a regex expression and use 
> it - however, it doesn't seem to work as planned:
>
> >>> pattern = re.compile(ham.regex_string)
> >>> print(pattern.match("22"))
> None
>
>
> Obviously if I pass the raw string literal in directly, it works fine:
>
> >>> pattern = re.compile(r'\d{2}')
> >>> pattern.match("22")
> <_sre.SRE_Match object at 0x1505100>
>
>
> If I actually print ham.regex_string, it returns:
>
> u"r'\\d{2}'"
>
>
> So it's a unicode string, but for some reason the backslashes are 
> doubled-up?
>
> What I actually need is a way to store a regex raw string literal, so that 
> I can retrieve it later and use it in a regex.
>
> Is there a better way of doing this?
>
> Cheers,
> Victor
>

So how did you save it in the first place? You don't actually want the `r` 
and the single quotes, they're just for when you specify the literal in your 
code. If you did 

foo.regex_string = r'\d{2}'

it should come out the other side OK. When you print the string in your 
console, it'll give the doubled-backslash, but that's just the way Python 
displays them - it would do the same with the original raw string.
--
DR.

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/qMNLMe601Y0J.
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.



Storing regex raw string literal in Django model?

2011-10-13 Thread Victor Hooi
Hi,

I have Django model and in one of the fields I need to store a regex string 
that I can later use.

class Foo(models.Model):
name = models.CharField(max_length=30, unique=True)
regex_string = models.TextField()


So for example, the regex_string field might be set to:

r'\d{2}'


I then try to retrieve this later, compile it as a regex expression and use 
it - however, it doesn't seem to work as planned:

>>> pattern = re.compile(ham.regex_string)
>>> print(pattern.match("22"))
None


Obviously if I pass the raw string literal in directly, it works fine:

>>> pattern = re.compile(r'\d{2}')
>>> pattern.match("22")
<_sre.SRE_Match object at 0x1505100>


If I actually print ham.regex_string, it returns:

u"r'\\d{2}'"


So it's a unicode string, but for some reason the backslashes are 
doubled-up?

What I actually need is a way to store a regex raw string literal, so that I 
can retrieve it later and use it in a regex.

Is there a better way of doing this?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/k7i1EJD2fVwJ.
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: Parenthesis in regex in URLConf

2011-05-23 Thread Pedram
Thanks but I still have problem.

My URLConf is like this:

Thank you very much.
Problem Solved :)

On May 23, 1:39 pm, Tom Evans <tevans...@googlemail.com> wrote:
> On Mon, May 23, 2011 at 10:25 AM, Pedram <pedrambehro...@gmail.com> wrote:
> > Hello,
> > I have a regular expression for usernames and I want to use this regex
> > in my URLConf and bind that to a view. The problem is, I have
> > parenthesis in my regex which should not consider as *args*. Here's my
> > regex:
>
> > ^[a-zA-Z0-9]+((\.[a-zA-Z0-9]+)|(_[a-zA-Z-0-9]+))*$
>
> > Values in '()' are necessary in my regex but I don't want to pass
> > these values to my view.
> > What should I do?
>
> http://docs.python.org/library/re.html
>
> (?:...)
> A non-capturing version of regular parentheses. Matches whatever
> regular expression is inside the parentheses, but the substring
> matched by the group cannot be retrieved after performing a match or
> referenced later in the pattern.
>
> Cheers
>
> Tom

-- 
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: Parenthesis in regex in URLConf

2011-05-23 Thread Tom Evans
On Mon, May 23, 2011 at 10:25 AM, Pedram <pedrambehro...@gmail.com> wrote:
> Hello,
> I have a regular expression for usernames and I want to use this regex
> in my URLConf and bind that to a view. The problem is, I have
> parenthesis in my regex which should not consider as *args*. Here's my
> regex:
>
> ^[a-zA-Z0-9]+((\.[a-zA-Z0-9]+)|(_[a-zA-Z-0-9]+))*$
>
> Values in '()' are necessary in my regex but I don't want to pass
> these values to my view.
> What should I do?
>

http://docs.python.org/library/re.html

(?:...)
A non-capturing version of regular parentheses. Matches whatever
regular expression is inside the parentheses, but the substring
matched by the group cannot be retrieved after performing a match or
referenced later in the pattern.

Cheers

Tom

-- 
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.



Parenthesis in regex in URLConf

2011-05-23 Thread Pedram
Hello,
I have a regular expression for usernames and I want to use this regex
in my URLConf and bind that to a view. The problem is, I have
parenthesis in my regex which should not consider as *args*. Here's my
regex:

^[a-zA-Z0-9]+((\.[a-zA-Z0-9]+)|(_[a-zA-Z-0-9]+))*$

Values in '()' are necessary in my regex but I don't want to pass
these values to my view.
What should I do?

-- 
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: Transform words into links with regex

2011-04-28 Thread Shawn Milochik
You need to use mark_safe. Otherwise Django will be protecting you from 
potential malicious input.


http://docs.djangoproject.com/en/1.3/ref/utils/#django.utils.safestring.mark_safe

--
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.



Transform words into links with regex

2011-04-28 Thread martinez
Hello. I am using Django 1.3 on Windows XP.
I read a tutorial and the code below transforms the words like MyLink
into a html link.
But the output that I achieved is the HTML markups of the link, not
the link itself.
How to solve that?
Thank you.

wikilink = re.compile("\\b([A-Z][a-z]+[A-Z][a-z]+)\\b")

register = template.Library()

@register.filter
def wikify(value):
return wikilink.sub(r"\1",value)

-- 
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: admin interface and urls.py regex issue

2011-04-03 Thread xiao_haozi


On Apr 3, 11:58 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Sun, Apr 3, 2011 at 11:35 PM, xiao_haozi <matthew.ma...@gmail.com> wrote:
> > I'm running into some perplexing regex issues in urls.py and getting
> > to my admin section.
> > It worked before but now that I have another view added in, anything
> > beyond the index regex is getting fed into the "url/" section rather
> > than admin:
>
> > I've included my urls.py section and the 500 error.
>
> > from django.conf.urls.defaults import patterns, include, url
>
> > # Uncomment the next two lines to enable the admin:
> > from django.contrib import admin
> > admin.autodiscover()
>
> > urlpatterns = patterns('',
> >    # Examples:
> >    # url(r'^
> > , 'Stumpy.views.home', name='home'),
> >    # url(r'^Stumpy/', include('Stumpy.foo.urls')),
>
> >    # show the index from /
> >    url(r'^, 'shortener.views.index'),
> >    # get a url for redirection /shorty
> >    url(r'^(?P\w+)/, 'shortener.views.detail'),
> >    # send a url to be shortened from /url/someencodedurl
> >    url(r'^url/(?P\S+)/, 'shortener.views.submit'),
>
> >    # Uncomment the admin/doc line below to enable admin
> > documentation:
> >    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
> >    # Uncomment the next line to enable the admin:
> >    url(r'^admin/', include(admin.site.urls)),
> > )
>
> > judging by the 500 error it seems to be sending it to the submit view
>
> No, the traceback below shows that the code is in the detail view.
>
>
>
> > Environment:
>
> > Request Method: GET
> > Request URL:http://192.168.11.4:8001/admin/
>
> > [snip]
> > Traceback:
> > File "/home/mugen/programming/django/django/core/handlers/base.py" in
> > get_response
> > 111. response = callback(request, callback_args, **callback_kwargs)
> > File "/home/mugen/programming/Stumpy/shortener/views.py" in detail
> > 11. thisurl = url.objects.get(shorturl=short) File "/home/mugen/
>
> line 111 in views.py i(n detail).
>
> Your urlpattern for this view is:
>
>    url(r'^(?P\w+)/, 'shortener.views.detail'),
>
> url patterns are scanned in order, and the first one that matches is used.
> /admin/ matches that regex.so detail is called.
>
> Either move the entry for admin above this one (in which case you can never
> have a short value of "admin"), leave it where it is and give it a different
> prefix than /admin/ -- one that will not match this detail pattern, or
> change this detail pattern so that /admin/ does not match it.
>
> (You should also fix your detail view so it does not generate a server error
> when called with a short value that does not exist...a 404 would be a more
> typical response to that situation.)
>
> Karen
> --http://tracey.org/kmt/

Another save.
Thanks again.

I should probably give it a rest for tonight at this rate.

I moved admin above and that now works as you suggested.
I will keep it like this for now and then work on creating a better
 regex (even though admin will never be used in this context).

As for the error return. That is next on my list. This is all just
coming together now and so errors are not being caught gracefully yet,
but rather spitting back a 500 error so I can see what's what. I'll
have this spit back a 404 next.

Thanks again for all your help. Much appreciated!

-- 
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: admin interface and urls.py regex issue

2011-04-03 Thread Karen Tracey
On Sun, Apr 3, 2011 at 11:35 PM, xiao_haozi <matthew.ma...@gmail.com> wrote:

> I'm running into some perplexing regex issues in urls.py and getting
> to my admin section.
> It worked before but now that I have another view added in, anything
> beyond the index regex is getting fed into the "url/" section rather
> than admin:
>
> I've included my urls.py section and the 500 error.
>
> from django.conf.urls.defaults import patterns, include, url
>
> # Uncomment the next two lines to enable the admin:
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
># Examples:
># url(r'^
> , 'Stumpy.views.home', name='home'),
># url(r'^Stumpy/', include('Stumpy.foo.urls')),
>
># show the index from /
>url(r'^, 'shortener.views.index'),
># get a url for redirection /shorty
>url(r'^(?P\w+)/, 'shortener.views.detail'),
># send a url to be shortened from /url/someencodedurl
>url(r'^url/(?P\S+)/, 'shortener.views.submit'),
>
># Uncomment the admin/doc line below to enable admin
> documentation:
>url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
># Uncomment the next line to enable the admin:
>url(r'^admin/', include(admin.site.urls)),
> )
>
>
> judging by the 500 error it seems to be sending it to the submit view
>

No, the traceback below shows that the code is in the detail view.


>
> Environment:
>
> Request Method: GET
> Request URL: http://192.168.11.4:8001/admin/
>
> [snip]
> Traceback:
> File "/home/mugen/programming/django/django/core/handlers/base.py" in
> get_response
> 111. response = callback(request, callback_args, **callback_kwargs)
> File "/home/mugen/programming/Stumpy/shortener/views.py" in detail
> 11. thisurl = url.objects.get(shorturl=short) File "/home/mugen/
>

line 111 in views.py i(n detail).

Your urlpattern for this view is:

   url(r'^(?P\w+)/, 'shortener.views.detail'),

url patterns are scanned in order, and the first one that matches is used.
/admin/ matches that regex.so detail is called.

Either move the entry for admin above this one (in which case you can never
have a short value of "admin"), leave it where it is and give it a different
prefix than /admin/ -- one that will not match this detail pattern, or
change this detail pattern so that /admin/ does not match it.

(You should also fix your detail view so it does not generate a server error
when called with a short value that does not exist...a 404 would be a more
typical response to that situation.)

Karen
-- 
http://tracey.org/kmt/

-- 
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.



admin interface and urls.py regex issue

2011-04-03 Thread xiao_haozi
I'm running into some perplexing regex issues in urls.py and getting
to my admin section.
It worked before but now that I have another view added in, anything
beyond the index regex is getting fed into the "url/" section rather
than admin:

I've included my urls.py section and the 500 error.

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'Stumpy.views.home', name='home'),
# url(r'^Stumpy/', include('Stumpy.foo.urls')),

# show the index from /
url(r'^$', 'shortener.views.index'),
# get a url for redirection /shorty
url(r'^(?P\w+)/$', 'shortener.views.detail'),
# send a url to be shortened from /url/someencodedurl
url(r'^url/(?P\S+)/$', 'shortener.views.submit'),

# Uncomment the admin/doc line below to enable admin
documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)


judging by the 500 error it seems to be sending it to the submit view

Environment:

Request Method: GET
Request URL: http://192.168.11.4:8001/admin/

Django Version: 1.3 SVN-16009
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites',
'django.contrib.messages', 'django.contrib.staticfiles',
'django.contrib.admin', 'django.contrib.admindocs', 'shortener']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "/home/mugen/programming/django/django/core/handlers/base.py" in
get_response
111. response = callback(request, callback_args, **callback_kwargs)
File "/home/mugen/programming/Stumpy/shortener/views.py" in detail
11. thisurl = url.objects.get(shorturl=short) File "/home/mugen/
programming/django/django/db/models/manager.py" in get
132. return self.get_query_set().get(args, **kwargs) File "/home/mugen/
programming/django/django/db/models/query.py" in get
349. % self.model._meta.object_name)

Exception Type: DoesNotExist at /admin/
Exception Value: url matching query does not exist.

-- 
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: compiled regex as attribute

2011-02-11 Thread Doug Ballance
Have you done any performance testing?  From what I understand pythons
re.compile caches internally, so after the first call subsequent calls
will use the pre-compiled expression.  Serializing the compiled
expression using pickle isn't 'free', so I'm wondering how much
difference there is in practice. Maybe a compromise of a normal model
text field storing the regular expression string you build when the
model is saved, and then a propery to simulate a read-only/don-demand
the compiled version when you need it.

ie something like:

class Product(models.Model):
   # ...
canonical_name = models.CharField(max_length=200)
spelling_variants = models.CharField(max_length=1, blank=True)
lexical_variants = models.CharField(max_length=1, blank=True)
excluded = models.CharField(max_length=1, blank=True)
permutations = models.CharField(max_length=1000, blank=True)
re_str=models.TextField()

compiled_re=property(lambda p: re.compile(p.re_str))

def save(self,*args,**kwargs):
# do your regular expression string build here and store in
self.re_str


Although it seems to me like each variant propably belongs as a
separate model, linking to your product.  That way you can search on
it, and add/remove variants fairly easily.  To match now, you'd have
to pull a bunch of products in a query and test each one.  The
database server isn't going to sweat a few hundred or even thousand
names.

class Variant(models.Model):
name=models.CharField(db_index=True)
product=models.ForeignKey(Product)

Product.objects.filter(variant__name='oha android 1.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-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: compiled regex as attribute

2011-02-11 Thread Javier Guerra Giraldez
On Fri, Feb 11, 2011 at 11:18 AM, Santiago Caracol
<santiago.cara...@gmail.com> wrote:
> There is no point in storing the regex strings in a pickle field. I
> already have the regex strings in ordinary django fields. What I want
> to store is *compiled* regular expressions in order to be able to use
> them without having to compile them first.

hum...  i wonder which takes more time, compiling the regex, or
unpickling it?  also, i guess the compiled+pickled regex is likely
much bigger than the original regex, so loading it means more disk
access

-- 
Javier

-- 
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: compiled regex as attribute

2011-02-11 Thread Tom Evans
On Fri, Feb 11, 2011 at 4:18 PM, Santiago Caracol
<santiago.cara...@gmail.com> wrote:
>> Since the pickled value is a string, it should work in fixtures.
>
> There is no point in storing the regex strings in a pickle field. I
> already have the regex strings in ordinary django fields. What I want
> to store is *compiled* regular expressions in order to be able to use
> them without having to compile them first.
>

It doesn't store the regex string, it stores the compiled regular
expression as a python object, pickled, and then packed into an ascii
string. When it pulls it out again, it unpacks it, un-pickles it and
it has a compiled regular expression, not a string.

Why don't you try it out and see, instead of just telling us it doesn't work.

Cheers

Tom

-- 
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: compiled regex as attribute

2011-02-11 Thread Shawn Milochik
You're forgetting the pickle part. That's what the getter and setter
are for in my previous description.

import re
import pickle

pattern = re.compile(r'^\w{3}\s+\d{3}')

x = pickle.dumps(pattern)

type(x)


If you store 'x' in your database you won't have any difficulty with fixtures.

Shawn

-- 
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: compiled regex as attribute

2011-02-11 Thread Santiago Caracol
> Since the pickled value is a string, it should work in fixtures.

There is no point in storing the regex strings in a pickle field. I
already have the regex strings in ordinary django fields. What I want
to store is *compiled* regular expressions in order to be able to use
them without having to compile them first.

-- 
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: compiled regex as attribute

2011-02-11 Thread Shawn Milochik
The picklefield stores strings. So when you say  "regexes can't be
stored in  fixtures," it implies that you're dealing with something
other than strings at that point. Have you tried the pickle field? As
I understand it, it's equivalent to this manual process:

Create a normal text field.

Make a property in your model that has getter and setter functions
which handle the pickling and unpickling.

(Recommended) Name the text field with an underscore as a prefix
to indicate that it's for internal use.

Since the pickled value is a string, it should work in fixtures.

Shawn

-- 
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: compiled regex as attribute

2011-02-11 Thread Santiago Caracol
> http://pypi.python.org/pypi/django-picklefield/0.1

Thanks for the tip. This works, but it has one great disadvantage: The
regexes can't be stored in fixtures. They are stored in the database
directly. So it seems I would have to insert all my several thousand
products manually again. And if I change some models and need to do a
"manage.py syncdb" all the work will be lost ...

Or is there a way of loading fixtures that includes that save() is
called for each loaded object?

-- 
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: compiled regex as attribute

2011-02-11 Thread Tom Evans
On Fri, Feb 11, 2011 at 9:47 AM, Santiago Caracol
<santiago.cara...@gmail.com> wrote:
> Hello,
>
> I have got objects with very large regular expressions:
>
> class Product(models.Model):
>   # ...
>    canonical_name = models.CharField(max_length=200)
>    spelling_variants = models.CharField(max_length=1, blank=True)
>    lexical_variants = models.CharField(max_length=1, blank=True)
>    excluded = models.CharField(max_length=1, blank=True)
>    permutations = models.CharField(max_length=1000, blank=True)
>
> When a product has values for all of the above attributes, it can
> calculate all its possible names. Example: the product 'google android
> 1.1' has several hundred possible names including these:
>
> google android-1.1, oha android-1.1, android-1.1, google android-1,1,
> oha android-1,1, android-1,1, google android-1-1, oha android-1-1,
> android-1-1, google android-11, oha android-11, android-11, google
> android-1 1, oha android-1 1, android-1 1, google android1.1, oha
> android1.1, android1.1, google android1,1, oha android1,1, android1,1,
> google android1-1, oha android1-1, android1-1, google android11, oha
> android11, android11, google android1 1, oha android1 1, android1 1,
> google android 1.1, oha android 1.1, android 1.1, google android 1,1,
> oha android 1,1,
>
> There are products with many more names. Consider the name of the
> mobile phone alcatatel one-touch-800-one-touch-chrome.
>
> Currently every product calculates all its possible names and a
> regular expression that includes the disjunction of all the possible
> names and compiles this regular expression at the time when the
> product is used. This is very inefficient. I would like to compile and
> store the regular expression only once: at the time when the new
> product is saved.
>
> However, there doesn't seem to be a models.RegexField. There is a
> forms.RegexField, but I don't understand how I could use it in the
> product model.
>
> Any tips how to store the compiled regex?
>
> Santiago
>

http://pypi.python.org/pypi/django-picklefield/0.1

Cheers

Tom

-- 
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.



compiled regex as attribute

2011-02-11 Thread Santiago Caracol
Hello,

I have got objects with very large regular expressions:

class Product(models.Model):
   # ...
canonical_name = models.CharField(max_length=200)
spelling_variants = models.CharField(max_length=1, blank=True)
lexical_variants = models.CharField(max_length=1, blank=True)
excluded = models.CharField(max_length=1, blank=True)
permutations = models.CharField(max_length=1000, blank=True)

When a product has values for all of the above attributes, it can
calculate all its possible names. Example: the product 'google android
1.1' has several hundred possible names including these:

google android-1.1, oha android-1.1, android-1.1, google android-1,1,
oha android-1,1, android-1,1, google android-1-1, oha android-1-1,
android-1-1, google android-11, oha android-11, android-11, google
android-1 1, oha android-1 1, android-1 1, google android1.1, oha
android1.1, android1.1, google android1,1, oha android1,1, android1,1,
google android1-1, oha android1-1, android1-1, google android11, oha
android11, android11, google android1 1, oha android1 1, android1 1,
google android 1.1, oha android 1.1, android 1.1, google android 1,1,
oha android 1,1,

There are products with many more names. Consider the name of the
mobile phone alcatatel one-touch-800-one-touch-chrome.

Currently every product calculates all its possible names and a
regular expression that includes the disjunction of all the possible
names and compiles this regular expression at the time when the
product is used. This is very inefficient. I would like to compile and
store the regular expression only once: at the time when the new
product is saved.

However, there doesn't seem to be a models.RegexField. There is a
forms.RegexField, but I don't understand how I could use it in the
product model.

Any tips how to store the compiled regex?

Santiago

-- 
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: Regex problem in urls

2010-07-30 Thread Alex Robbins
Based on the urls.py file you are showing us, it seems like /start/
should be a valid url.

Are you running the dev server with automatic reloading? Sometimes you
need to force a reload on it to see changes. (I normally notice that
in the admin, but it could come up anywhere stuff gets cached in
memory for performance on startup).

Alex

On Jul 29, 4:18 pm, Gordy <gor...@sunporchanalytics.com> wrote:
> I'm a rookie at Django so this is probably something obvious.
>
> My urls.py looks like this:
>
> 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'^sunlight/', include('sunlight.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/(.*)', 'admin.site.root'),
>     (r'^start/', 'sunlight.start.views.index'),
>     (r'req/','sunlight.requests.views.index'),
> )
> ~
>
> When I hit the site, I get:
>
> Page not found (404)
> Request Method:         GET
> Request URL:    http://server2/start/
>
> Using the URLconf defined in sunlight.urls, Django tried these URL
> patterns, in this order:
>
>    1. ^admin/doc/
>    2. ^admin/(.*)
>    3. ^[/]$
>    4. req/
>
> The current URL, start/, didn't match any of these.
>
> So it looks like it isn't properly interpreting the regex on line 3.
>
> Any help would be appreciated.

-- 
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.



Regex problem in urls

2010-07-29 Thread Gordy
I'm a rookie at Django so this is probably something obvious.

My urls.py looks like this:

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'^sunlight/', include('sunlight.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/(.*)', 'admin.site.root'),
(r'^start/', 'sunlight.start.views.index'),
(r'req/','sunlight.requests.views.index'),
)
~


When I hit the site, I get:

Page not found (404)
Request Method: GET
Request URL:http://server2/start/

Using the URLconf defined in sunlight.urls, Django tried these URL
patterns, in this order:

   1. ^admin/doc/
   2. ^admin/(.*)
   3. ^[/]$
   4. req/

The current URL, start/, didn't match any of these.

So it looks like it isn't properly interpreting the regex on line 3.

Any help would be appreciated.

-- 
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: URLs and Regex Question for passing email address?

2010-02-15 Thread Karen Tracey
On Mon, Feb 15, 2010 at 6:06 AM, Jonathan Sutcliffe <
jonosutcli...@googlemail.com> wrote:

>
> I want to pass a URL of the following form, containing an email
> address that I will later look up contact information from.
>
> e.g.  http://localhost:8000/contact/ronald.ninnis%40cdu.edu.au/
>
> I don't care about whether this is a valid email string I simple want
> to pass the parameter across to the view and do the look up here.
>
> I notice the @ is already %40 which has been escaped by the Javascript
> in the calling application.
>
> In my urls.py I have the following regex.
>
> urls.py
>
>  (r'^contact/(?P\[a-z0-9._%+...@[a-z0-9.-]+\.[a-z]{2,4})/$',
> 'entitlements.sfdc.views.contactdetail'),
>
> But no match is found. Could someone point out the error of my ways?
>

If you do not care if it is a valid email string why are you attempting any
kind of 'looks like an email' matching in the url pattern?

As for what, specifically, is wrong with that pattern -- the \ after 
looks wrong, and the fact that you've specified all uppercase letters to
match yet the sample URL you show has lowercase letters looks like a
problem, for starters. But really I would hesitate to try to 'fix' that
pattern, particularly if you really don't care if it is a valid email
address at this point in the code. Just switch it to something that accepts
anything between the two slashes in the url, and if you do care about
checking validity later in processing, use some other pre-existing email
validation code to check the value once you've got it in the view.

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: URLs and Regex Question for passing email address?

2010-02-15 Thread Shawn Milochik
It sounds like this might be a good case for a GET (querystring).

As in:

 http://localhost:8000/contact/?email=ronald.ninnis%40cdu.edu.au/

Then use something like request.GET.get('email', '') to get the value.
That seems easier and cleaner than trying to have a URL pattern regex match 
every valid e-mail address.

Shawn

-- 
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.



URLs and Regex Question for passing email address?

2010-02-15 Thread Jonathan Sutcliffe
Hi,

I am new to Django and Python and have what must be a basic question.

I want to pass a URL of the following form, containing an email
address that I will later look up contact information from.

e.g.  http://localhost:8000/contact/ronald.ninnis%40cdu.edu.au/

I don't care about whether this is a valid email string I simple want
to pass the parameter across to the view and do the look up here.

I notice the @ is already %40 which has been escaped by the Javascript
in the calling application.

In my urls.py I have the following regex.

urls.py

  (r'^contact/(?P\[a-z0-9._%+...@[a-z0-9.-]+\.[a-z]{2,4})/$',
'entitlements.sfdc.views.contactdetail'),

But no match is found. Could someone point out the error of my ways?

Many Thanks,
Jono

-- 
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: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?

2009-10-12 Thread Tom Evans

On Fri, 2009-10-09 at 12:21 -0700, davisd wrote:
> Sorry for the public disclosure...  I did email django security after
> I posted.  I'm just getting into this open source goodness and I'm not
> really sure how it's supposed to operate yet.
> 
> I did consult the documentation: 
> http://docs.djangoproject.com/en/dev/internals/contributing/
> 
> Jacob:
> I'm running django from SVN
> Python 2.6.2
> I believe the Operating system is moot- it's all in the python.
> Linux kernel 2.6.31-11, but also 2.6.18.8 -
> 
> I'm wondering if a multithreaded webserver setup would be more guarded
> against this sort of thing?
> 

This bug has no effect on FreeBSD systems I've tested, so it looks like
it is OS specific.

FreeBSD 7.0, 7.1, 7.2 + python 2.5.4 work fine.

> $ time python -c "from django.forms.fields import email_re; 
> email_re.match('viewx3dtextx26q...@yahoo.comx26latlngx3d15854521645943074058');
>  import django; print django.VERSION"
(1, 1, 0, 'final', 0)

real0m0.086s
user0m0.055s
sys 0m0.029s


Linux 2.6.27 + python 2.5.4 fails.

> $ time python -c "from django.forms.fields import email_re; 
> email_re.match('viewx3dtextx26q...@yahoo.comx26latlngx3d15854521645943074058');
>  import django; print django.VERSION"
^CTraceback (most recent call last):
  File "", line 1, in 
KeyboardInterrupt

real0m21.317s
user0m21.173s
sys 0m0.044s


Cheers

Tom


--~--~-~--~~~---~--~~
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: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?

2009-10-09 Thread Jacob Kaplan-Moss

Just as an update for anyone following this thread:

This was indeed a security exploit, and it has been fixed. See
http://www.djangoproject.com/weblog/2009/oct/09/security/ for details.

Jacob

--~--~-~--~~~---~--~~
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: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?

2009-10-09 Thread Karen Tracey
On Fri, Oct 9, 2009 at 3:21 PM, davisd  wrote:

>
> I'm wondering if a multithreaded webserver setup would be more guarded
> against this sort of thing?
>
>
Yeah, but.  When I tried this on my own production server (Apache/mod_wsgi)
the process handling the request that caused the problem was killed after
the deadlock timeout was reached. But deadlock timeout can't really protect
you from a determined denial of service attack, so it's still a problem in
Django.

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-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: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?

2009-10-09 Thread davisd

Sorry for the public disclosure...  I did email django security after
I posted.  I'm just getting into this open source goodness and I'm not
really sure how it's supposed to operate yet.

I did consult the documentation: 
http://docs.djangoproject.com/en/dev/internals/contributing/

Jacob:
I'm running django from SVN
Python 2.6.2
I believe the Operating system is moot- it's all in the python.
Linux kernel 2.6.31-11, but also 2.6.18.8 -

I'm wondering if a multithreaded webserver setup would be more guarded
against this sort of thing?


On Oct 9, 2:18 pm, James Bennett  wrote:
> Yes.
>
> We've confirmed the problem. We're working on a patch.
>
> In the meantime, everybody go meditate on the documentation for how to
> report security issues.
>
> --
> "Bureaucrat Conrad, you are technically correct -- the best kind of correct."
--~--~-~--~~~---~--~~
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: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?

2009-10-09 Thread James Bennett

Yes.

We've confirmed the problem. We're working on a patch.

In the meantime, everybody go meditate on the documentation for how to
report security issues.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?

2009-10-09 Thread Juan Hernandez
Take a look at mine:

*In [41]: from django.forms.fields
django.forms.fields

In [41]: from django.forms.fields import email_re

In [42]:
email_re.match('viewx3dtextx26q...@yahoo.comx26latlngx3d15854521645943074058
')*

and this is what top shows:
*
  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+
COMMAND
13886 juan  20   0 17556  12m 1992 R   95  1.3   0:59.61 ipyth*on

and stays like that for ever...

--~--~-~--~~~---~--~~
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: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?

2009-10-09 Thread davisd

Ok!  I just confirmed this, I took down a live server! (On of my own)

All I had to do was put the email address in the contact form.

-David

On Oct 9, 1:13 pm, davisd <davisd.dav...@gmail.com> wrote:
> After hours of debugging, I found that:
>
> from django.forms.fields import email_re
> email_re.match
> ('viewx3dtextx26q...@yahoo.comx26latlngx3d15854521645943074058')
>
> will cause CPU to shoot up 100% and the process will hang forever.
>
> Since this is the regex used to validate EmailField on forms, won't
> this DOS a live site?
>
> Where should I report this?
>
> Is there a better way to validate an email address?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?

2009-10-09 Thread davisd

After hours of debugging, I found that:

from django.forms.fields import email_re
email_re.match
('viewx3dtextx26q...@yahoo.comx26latlngx3d15854521645943074058')

will cause CPU to shoot up 100% and the process will hang forever.

Since this is the regex used to validate EmailField on forms, won't
this DOS a live site?

Where should I report this?

Is there a better way to validate an email address?
--~--~-~--~~~---~--~~
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: Q regex

2009-10-06 Thread Tim Chase

Karen Tracey wrote:
> On Tue, Oct 6, 2009 at 1:32 PM, Mat  wrote:
> 
>> Okay so here is my code:
>>
>> **This way works and does not error**
>> rs = BadActor.objects.filter(addr__iregex='^(192\.188\.)(.*)(\.20)$');
>> print len(rs);
>> print rs[0].addr
>>
>> ***This way errors
>> q = Q({'addr__iregex':'^(192\.188\.)(.*)(\.20)$'});
>>
> 
> Why the dict?  Why not simply:
> 
> q = Q(addr__iregex='^(192\.188\.)(.*)(\.20)$')

You'll also want to use python's "raw" strings for regexps...this 
isn't the regexp you think it is.  You likely want

   r'^(192\.188\.)(.*)(\.20)$'

As your pattern was originally, the "\." bits get unescaped as 
just "." because there is no "\." escape-character.  It then 
becomes just "^(192.188.)(.*)(.20)$" and would match

   192Z188Xabcdefg920
   [..][.][.] <- matched groups

which I don't think is what you meant.  And as one other aside, 
do you mean "192.168" (a popular private subnet block) instead of 
"192.188"?  Though this is just a matter of what you mean, and 
you may really mean "192.188"

-tim




--~--~-~--~~~---~--~~
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: Q regex

2009-10-06 Thread Karen Tracey
On Tue, Oct 6, 2009 at 1:32 PM, Mat  wrote:

>
> Okay so here is my code:
>
> **This way works and does not error**
> rs = BadActor.objects.filter(addr__iregex='^(192\.188\.)(.*)(\.20)$');
> print len(rs);
> print rs[0].addr
>
> ***This way errors
> q = Q({'addr__iregex':'^(192\.188\.)(.*)(\.20)$'});
>

Why the dict?  Why not simply:

q = Q(addr__iregex='^(192\.188\.)(.*)(\.20)$')

If you have a dict that you want to pass as keyword args, you need to use
**:

q = Q(**{'addr__iregex':'^(192\.188\.)(.*)(\.20)$'});

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-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
-~--~~~~--~~--~--~---



Q regex

2009-10-06 Thread Mat

Okay so here is my code:

**This way works and does not error**
rs = BadActor.objects.filter(addr__iregex='^(192\.188\.)(.*)(\.20)$');
print len(rs);
print rs[0].addr

***This way errors
q = Q({'addr__iregex':'^(192\.188\.)(.*)(\.20)$'});
rs = BadActor.objects.filter(q);
print len(rs);
print rs[0].addr

**THE ERROR MESSAGE*
Request Method: GET
Request URL:http://127.0.0.1:8000/federated/repo/search/alerts/
Exception Type: ValueError
Exception Value:

need more than 1 value to unpack

Exception Location: /usr/lib/python2.5/site-packages/django/db/models/
sql/query.py in add_filter, line 1155
Python Executable:  /usr/bin/python
Python Version: 2.5.4

END Error

So what am i doing wrong?

--~--~-~--~~~---~--~~
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: regex query delivering incorrect results

2009-09-29 Thread janedenone

Hi Karen,

On 28 Sep., 22:49, Karen Tracey  wrote:
> On Mon, Sep 28, 2009 at 4:00 PM, janedenone wrote:
>
> > Hi,
>
> > this
>
> > pages = Page.objects.exclude(content__iregex=r'^[\n\r \t]*<')
>
> > should deliver the same rows as this
>
> > SELECT ... FROM pages WHERE (content NOT REGEXP '^[\n\r \t]*<')
>
> > but it does not: The Django query delivers 468 rows, whereas the SQL
> > query delivers 223. It could be that the Django query does not
> > recognize line endings as mentioned in the character class. Am I
> > missing something?
>
> The Django query is going to be an SQL query also.  To see what Django is
> sending to the DB you should recreate in a shell session and then:
>
> >>> from django.db import connection
> >>> connection.queries[-1]
>
> to see how the query you are expecting compares to the query that is
> actually being issued.  (Note the sql in connection.queries won't have the
> necessary quotes around the regexp parameter -- this quoting is done by the
> backend and therefore not logged in the version stored in
> connection.queries).
>

Thanks a lot! I am aware that Django creates SQL queries for me, but I
did not know how to make them visible. connection.queries shows that
the backslashes preceding my special characters had been escaped:

u'SELECT ... WHERE (NOT (`pages`.`content` REGEXP ^[\\n\\r \\t]*< )
AND NOT (`pages`.`content` REGEXP ^[\\n\\r \\t]*$ )

and I fixed this by changing the Django expression from

pages = Page.objects.exclude(content__iregex=r'^[\n\r \t]*<').exclude
(content__iregex=r'^[\n\r \t]*$')

to

pages = Page.objects.exclude(content__iregex=u'^[\n\r \t]*<').exclude
(content__iregex=u'^[\n\r \t]*$')

Thanks again,
Jan
--~--~-~--~~~---~--~~
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: regex query delivering incorrect results

2009-09-28 Thread Karen Tracey
On Mon, Sep 28, 2009 at 4:00 PM, janedenone wrote:

>
> Hi,
>
> this
>
> pages = Page.objects.exclude(content__iregex=r'^[\n\r \t]*<')
>
> should deliver the same rows as this
>
> SELECT ... FROM pages WHERE (content NOT REGEXP '^[\n\r \t]*<')
>
> but it does not: The Django query delivers 468 rows, whereas the SQL
> query delivers 223. It could be that the Django query does not
> recognize line endings as mentioned in the character class. Am I
> missing something?
>
>
The Django query is going to be an SQL query also.  To see what Django is
sending to the DB you should recreate in a shell session and then:

>>> from django.db import connection
>>> connection.queries[-1]

to see how the query you are expecting compares to the query that is
actually being issued.  (Note the sql in connection.queries won't have the
necessary quotes around the regexp parameter -- this quoting is done by the
backend and therefore not logged in the version stored in
connection.queries).

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-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
-~--~~~~--~~--~--~---



regex query delivering incorrect results

2009-09-28 Thread janedenone

Hi,

this

pages = Page.objects.exclude(content__iregex=r'^[\n\r \t]*<')

should deliver the same rows as this

SELECT ... FROM pages WHERE (content NOT REGEXP '^[\n\r \t]*<')

but it does not: The Django query delivers 468 rows, whereas the SQL
query delivers 223. It could be that the Django query does not
recognize line endings as mentioned in the character class. Am I
missing something?

Kind regards,
Jan
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Unicode [i]regex + sqlite3

2009-09-08 Thread matevzb

I've run into a strange problem using Django's [i]regex search with
non-ascii characters.
I'm using the [i]regex in the following manner:
 begin code 
class Tag(models.Model):
  def __unicode__(self):
return self.keyword
  keyword = models.CharField(max_length=64)

kwlist = [some list of keywords]
tag_query = Q()
for k in kwlist:
  rx = r'\b' + k + r'\b'
  tag_query = tag_query | Q(keyword__iregex=rx)  # or keyword__regex,
neither works

for t in Tag.objects.filter(tag_query):
  print t
 end code 

When a Tag's keyword *begins* with a non-ascii character (e.g. in my
case \u010d, which
is "latin small letter c with caron"), the [i]regex lookup fails for
some reason.
The strange thing is that there seem to be no problems with words
containing such characters
elsewhere, i.e. not at the beginning of a string. I've also tried the
following:
- Q(keyword__iexact), works OK
- modified regex: r'\b.*' + k[1:] + r'\b' works OK, but obviously may
return many false positives
- modified regex: r'\b.' + k[1:] + r'\b' doesn't work(?)
- python's re.search() works OK on such strings

Is this a known issue with Django + sqlite3 combination? I've seen the
docs mention that
iexact might be problematic, but that one actually works fine.

I'm using Django 1.0.2 with sqlite3 3.4.0 and python 2.5.1 (Mac OS X
10.5).

--~--~-~--~~~---~--~~
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: regex problem in urls.py in Django 1.1/mod_wsgi

2009-09-06 Thread Jim Myers

My noob error: I had extra "portal/" on my regex.
Sorry and thanks for your attention.

--~--~-~--~~~---~--~~
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: regex problem in urls.py in Django 1.1/mod_wsgi

2009-09-06 Thread Graham Dumpleton



On Sep 6, 3:52 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Sun, Sep 6, 2009 at 1:36 AM, Jim Myers <myer...@gmail.com> wrote:
>
> > Thanks, but that doesn't do it either.
> > I changed the regex to:
>
> > ^portal/student/(?P\S+)/profile_edit/$
>
> > and it still doesn't match :(
>
> It should:
>
> >>> import re
> >>> re.match(r'^portal/student/(?P\S+)/profile_edit/$',
>
> 'portal/student/xx.yy/profile_edit/').groupdict()
> {'userid': 'xx.yy'}
>
>
>
> I don't know what to tell you. The regex now matches the url you specified.
> url mapping isn't fundamentally broken in Django.  There's got to be
> something else going on in your scenario...

There is always the failing to restart Apache after changes
option. ;-)

Graham

> Karen
>
> On Sep 5, 9:44 pm, Karen Tracey <kmtra...@gmail.com> wrote:
>
>
>
> > > On Sat, Sep 5, 2009 at 11:32 PM, Jim Myers <myer...@gmail.com> wrote:
>
> > > > Hi, I'm using this regex in urls.py:
>
> > > > r'^portal/student/(?P\S+)/profile_edit$'
>
> > > > There's no trailing slash on this regex, but there is an end of string
>
> > > marker ($). So a match will have to end with 'profile_edit', no trailing
> > > slash.
>
> > > > to try to match this url:
>
> > > >http://dd..org/portal/student/xx.yy/profile_edit/
>
> > > This url ends with a trailing slash, thus won't match the above regex.
>
> > > 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-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: regex problem in urls.py in Django 1.1/mod_wsgi

2009-09-05 Thread Jim Myers

Thanks, but that doesn't do it either.
I changed the regex to:

^portal/student/(?P\S+)/profile_edit/$

and it still doesn't match :(

On Sep 5, 9:44 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Sat, Sep 5, 2009 at 11:32 PM, Jim Myers <myer...@gmail.com> wrote:
>
> > Hi, I'm using this regex in urls.py:
>
> > r'^portal/student/(?P\S+)/profile_edit$'
>
> > There's no trailing slash on this regex, but there is an end of string
>
> marker ($). So a match will have to end with 'profile_edit', no trailing
> slash.
>
> > to try to match this url:
>
> >http://dd..org/portal/student/xx.yy/profile_edit/
>
> This url ends with a trailing slash, thus won't match the above regex.
>
> 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-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: regex problem in urls.py in Django 1.1/mod_wsgi

2009-09-05 Thread Karen Tracey
On Sat, Sep 5, 2009 at 11:32 PM, Jim Myers <myer...@gmail.com> wrote:

>
> Hi, I'm using this regex in urls.py:
>
> r'^portal/student/(?P\S+)/profile_edit$'
>
> There's no trailing slash on this regex, but there is an end of string
marker ($). So a match will have to end with 'profile_edit', no trailing
slash.


> to try to match this url:
>
> http://dd..org/portal/student/xx.yy/profile_edit/
>
>
This url ends with a trailing slash, thus won't match the above regex.

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-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
-~--~~~~--~~--~--~---



regex problem in urls.py in Django 1.1/mod_wsgi

2009-09-05 Thread Jim Myers

Hi, I'm using this regex in urls.py:

r'^portal/student/(?P\S+)/profile_edit$'

to try to match this url:

http://dd..org/portal/student/xx.yy/profile_edit/

It's supposed to put "xx.yy" into userid parameter and match and use
the associated view.

But it doesn't match. I've banged my head for hours with regexes and
don't see why not.

Why won't this work?  Should I be doing this a better 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: regex problem in django

2009-06-29 Thread James Gregory



On Jun 29, 2:57 pm, Joru <avenp...@gmail.com> wrote:
> Still doesn't work even I remove wrap function :(

So it seems your regex is incorrect, the problem is not related to
Django. If you paste your code here I can have a look, but I still
think you'd be better off reading a bit more about regular expressions
yourself. The last link I posted wasn't very useful for learning
because it is just a reference, there is a proper tutorial on regular
expressions with Python here:

http://www.amk.ca/python/howto/regex/

James
--~--~-~--~~~---~--~~
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: regex problem in django

2009-06-29 Thread Joru

Still doesn't work even I remove wrap function :(

On Jun 29, 7:35 pm, James Gregory  wrote:
> On Jun 29, 1:05 pm, Joru  wrote:
>
> > I'm sorry for my typo
> > the string var suppose to be like this
> > str = "wr:\n one bunny \n two bunny \n wr:\n three bunny \n
> > So every match string "wr:" should had "+" in front of it line
> > the one that confuse me is that my function work in django/python
> > shell, but thisregexdoesn't work well if i called it from views.py
> > of my django app
> > So the problem that I faced is that, how come when using django/python
> > shell. myregexwork but not if I put in on my views.py
> > Any hint?
>
> I may be wrong, but I suspect there is a difference between the input
> string/code you are using in the shell, and the input string/code you
> are using in the view. What happens if make a new empty Python script
> and cut and paste in your code (removing the wrap function from
> Django). Does it work then?
>
> James
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



  1   2   3   >