Marten,


As you likely remember, I've been running your code for a few months now, 
overall it's been pretty good. I mentioned some time ago that the list of 
URLs displayed with `DEBUG=True` when triggering a 404 is sometimes empty, 
or partially empty. This still happens for me, and I believe it has 
something to do with using scheme/domain constraints - here are mine:

class ConstraintBase(Constraint):
    """
    This exists purely as a way to ensure MRO mixin inheritance will work
    """
    def match(self, path, request=None):
        return path, (), {}

    def construct(self, url_object, *args, **kwargs):
        return url_object, args, kwargs


class SchemeConstraintMixin(object):
    scheme = ''

    def match(self, path, request=None):
        if request and request.scheme == self.scheme:
            return super().match(path, request)
        raise Resolver404

    def construct(self, url_object, *args, **kwargs):
        url_object.scheme = self.scheme
        return super().construct(url_object, *args, **kwargs)


class HostConstraintMixin(object):
    host = ''

    def match(self, path, request=None):
        if request and request.get_host() == self.host:
            return super().match(path, request)
        raise Resolver404

    def construct(self, url_object, *args, **kwargs):
        url_object.host = self.host
        return super().construct(url_object, *args, **kwargs)


class SchemeHostConstraint(SchemeConstraintMixin, HostConstraintMixin, 
ConstraintBase):
    def __init__(self, scheme, host):
        self.scheme = scheme
        self.host = host


www_urlpatterns = [
    url(r'^$', images_views.photos, {'template': 'images/homepage.html'}, 
name='homepage'),
    url(r'^users/', include('users.urls.profiles')),
    url(r'^blog/', include('writing.urls.content'), {'section_slug': 'blog'}),
    url(r'^galleries/', include('writing.urls.content'), {'section_slug': 
'galleries'}),
    url(r'^writers/', include('writing.urls.authors')),
    url(r'^', include('vendors.urls.www')),
    url(r'^', include('images.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

my_urlpatterns = [
    url(r'^', include('users.urls.my')),
    url(r'^businesses/', include('vendors.urls.my')),
    url(r'^user/', include('users.urls.auth')),
    url(r'^user/', include('users.urls.social')),
]

manage_urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
]

payments_urlpatterns = [
    url(r'^braintree/', include('payments.urls.payments_braintree')),
]

urlpatterns = [
    # non-logged in pages; public facing and indexable by search engines
    url(SchemeHostConstraint(*settings.SITE_DOMAIN_WWW), 
include(www_urlpatterns)),
    # logged in users only, public facing and not indexable by search engines 
(perhaps some exceptions...)
    url(SchemeHostConstraint(*settings.SITE_DOMAIN_MY), 
include(my_urlpatterns)),
    # staff only; logged in users only; Django admin + custom management pages
    url(SchemeHostConstraint(*settings.SITE_DOMAIN_MANAGE), 
include(manage_urlpatterns)),
    # webhooks for payment processing
    url(SchemeHostConstraint(*settings.SITE_DOMAIN_PAYMENTS), 
include(payments_urlpatterns))
]


Relevant settings:

SITE_DOMAIN_MY = ('http', 'mylocal.project.com:9000')
SITE_DOMAIN_WWW = ('http', 'wwwlocal.project.com:9000')
SITE_DOMAIN_MANAGE = ('http', 'managelocal.project.com:9000')
SITE_DOMAIN_PAYMENTS = ('http', 'paymentslocal.project.com:9000')


I'm running this within a vagrant/virtualbox setup, hence the `:9000` port. 
That said, this still happens on our preview server.

Just today, however, I was wondering why `APPEND_SLASH=True` was no longer 
having an effect - no redirection happens. I *think* it is due to the 
`CommonMiddleware` code 
here 
https://github.com/knbk/django/blob/dispatcher_api/django/middleware/common.py#L75.
 
As both `request.get_full_path()` and `request.path_info` do not include 
the scheme or domain, using `is_valid_path()` will fail. Is this correct?

Cheers,
James




On Friday, January 8, 2016 at 8:46:39 AM UTC-8, Marten Kenbeek wrote:
>
> The first argument to Constraint.construct() is a URL helper object which 
> allows you to set the scheme, host, path, querystring and fragment 
> separately. So reversing a domain constraint is as simple as this:
>
> class DomainConstraint(Constraint):
>     ...
>     def construct(self, url_object, *args, **kwargs):
>         url_object.host = self.domain
>         return url_object, args, kwargs
>
>
> On Thursday, January 7, 2016 at 2:07:03 PM UTC+1, Florian Apolloner wrote:
>>
>>
>>
>> On Monday, December 28, 2015 at 5:23:19 PM UTC+1, Marten Kenbeek wrote:
>>>
>>> One can for example implement a DomainConstraint or MethodConstraint to 
>>> match a domain name or request method in the URL, or implement a set of 
>>> constraints based on the parse library for better performance than the 
>>> built-in regex-based constraints.
>>>
>>
>> A method constraint seems simple enough, how would the domain constraint 
>> work with regards to reversing -- do you have an example for that?
>>
>> Cheers,
>> Florian
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/0b3ae165-c1ba-419e-ba0a-4a28c0b61bb3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to