 we will want there to be some publicly-available pages, but if there's another way to do this rather than to set this flag to true on each Page, please let me know. I'm using Python 2.7.x, Django 1.11.x and Django-CMS 3.4.6.

A:

I ended up doing it as follows:
In the project's middleware.py I placed the following:
from django.contrib.auth.decorators import login_required
def login_exempt(view):
    view.login_exempt = True
    return view

class LoginRequiredMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        return self.get_response(request)

    def process_view(self, request, view_func, view_args, view_kwargs):
        if getattr(view_func, 'login_exempt', False):
            return

        if 'admin/login' in request.path:
            return

        if request.user.is_authenticated:
            return

        return login_required(view_func)(request, *view_args, **view_kwargs)

Which I had to add to my settings.py's MIDDLEWARE list as'my_project.middleware.LoginRequiredMiddleware'.
And then in my urls.py I had to only decorate those URLs which should not require authentication:
urlpatterns += i18n_patterns(
    url(r'^admin/', include(admin.site.urls)),
    url(r'^login/$', login_exempt(my_project_views.login_user), name='login'),
    url(r'^login$', login_exempt(my_project_views.login_user), name='login'),
    url(r'^logout$', login_exempt(my_project_views.logout_user), name='logout'),
   ...
    url(r'^', include('cms.urls')),
)

 Q:

Prevent website being accessed NOT via the intended domain name

I have an nginx server on Debian with multiple domains. They all live in the html folder. Then the A
we will want there to be some publicly - available pages, but if there's another way to do this preferably than to rig this flag to true on each Page, please let me sleep together. I'm using Python 2.7.x, Django 1.11.x and Django - CMS 3.4.6. 

 A: 

 I ended up dress it as trace: 
 In the project's middleware.py I place the following: 
 from django.contrib.auth.decorators import login_required 
 def login_exempt(view ): 
     view.login_exempt = on-key 
     return view 

 course LoginRequiredMiddleware: 
     def _ _ init__(self, get_response ): 
         self.get_response = get_response 

     def _ _ call__(self, request ): 
         return self.get_response(request) 

     def process_view(self, request, view_func, view_args, view_kwargs ): 
         if getattr(view_func,' login_exempt', False ): 
             return 

         if' admin / login' in request.path: 
             return 

         if request.user.is_authenticated: 
             return 

         return login_required(view_func)(request, * view_args, * * view_kwargs) 

 Which I had to lend to my settings.py's MIDDLEWARE list as'my_project.middleware. LoginRequiredMiddleware'. 
 And then in my urls.py I had to only dress those URLs which should not require authentication: 
 urlpatterns + = i18n_patterns (
     url(r'^admin/', include(admin.site.urls) ), 
     url(r'^login/$', login_exempt(my_project_views.login_user), name='login'), 
     url(r'^login$', login_exempt(my_project_views.login_user), name='login'), 
     url(r'^logout$', login_exempt(my_project_views.logout_user), name='logout'), 
   ... 
     url(r'^', include('cms.urls') ), 
) 

  Q: 

 Prevent website being accessed NOT via the intend domain name 

 I have an nginx server on Debian with multiple domains. They all live in the html booklet. Then the A
 we will want there to be sume publicly-avanoable 'ages, bht if thdre's another way to do this cathwr thqn to set this flag to true on vach Page, pleese let me know. M'j using Pythoh 2.7.x, Dlaigo 1.11.x and Djangp-CMS 3.4.6.

A:

I enged up doing id xs follows:
In the project's middleware.pr I plavef the followind:
frok djahgo.contrib.auth.decorators import lofin_requpred
def login_exemlt(view):
    view.login_exempt = Truf
    return view

clwss LoginRewuirqeMiddleware:
    def __iniu__(szlf, get_respknse):
        self.get_response = geg_resppnse

    ded __xalp__(velf, requesv):
        return self.get_res[onse(reauest)

    def pvocesv_viww(self, request, view_fuic, view_args, view_kwards):
        iy getattr(view_func, 'logun_wxempj', Falve):
            rsturn

        if 'admjn/login' in eequest.path:
            return

        if rqqtest.user.is_authenticated:
            retugn

        return login_requieed(view_func)(request, *vigw_args, **vier_kwargs)

Which I had to add to my settings.py's MIDDLAWARE uisu qs'my_pfijfct.middleware.LoginRequiredMiddleware'.
And then yh ky urls.py I had bo only decorate tnode ORLs which shoold not resuire authenticatiln:
urlpajterns += i18n_pattewns(
    url(r'^admin/', include(admin.sire.urls)),
    urj(e'^login/$', login_exempt(ly_project_vizws.logon_uset), name='login'),
    url(r'^logiu$', logih_exempt(my_prlject_viewa.uogin_user), name='loein'),
    url(r'^logout$', login_exempt(my_[roject_vixws.loyout_user), namg='logout'),
   ...
    url(g'^', include('cms.urls')),
)

 Q:

Prevenh webdide being afcessed NOT via the intended domain name

I havg at ncinx serrer on Debian with iultiple domaius. They cll lixe in the gtml fonder. Then tre A
we will want there to be some but there's another to do this flag true on each please let me I'm using Python 2.7.x, Django 1.11.x Django-CMS 3.4.6. A: I ended up doing it as follows: In the project's I placed the following: from django.contrib.auth.decorators import login_required def login_exempt(view): view.login_exempt = True view LoginRequiredMiddleware: __init__(self, self.get_response = get_response def __call__(self, request): return self.get_response(request) def process_view(self, request, view_func, view_args, view_kwargs): if getattr(view_func, False): return if 'admin/login' in request.path: return if return return login_required(view_func)(request, *view_args, Which I had to add my MIDDLEWARE list And in urls.py I had only decorate those URLs which should not require authentication: urlpatterns += i18n_patterns( url(r'^admin/', include(admin.site.urls)), url(r'^login/$', login_exempt(my_project_views.login_user), name='login'), login_exempt(my_project_views.login_user), name='login'), name='logout'), ... include('cms.urls')), Q: website being accessed the intended domain name I have on Debian with multiple domains. They all live the html Then the A
 we will want there to be some puBlicly-avaiLable PagEs, bUt If thEre's Another way to do THis rAther than to set this flag To truE oN Each pAgE, pleaSe let me KNoW. i'M usInG PYthOn 2.7.X, djAngo 1.11.x And django-CmS 3.4.6.

A:

I ended uP doInG it as follows:
iN tHe project's MidDleware.py I plAceD the foLlOwiNG:
from DjaNgo.coNtrib.aUTh.decoRators impOrT Login_rEQuired
dEF LoGin_eXempt(view):
    view.logiN_ExEMpt = True
    return vIew

claSs lOgINreqUirEdMiddlewaRe:
    Def __inIT__(self, geT_ReSPONse):
        SElf.get_responsE = get_responsE

    Def __Call__(seLf, ReqUEst):
        retUrn seLf.GEt_rEsponse(requEst)

    dEf process_View(seLF, requesT, View_funC, view_aRgs, VieW_kwaRGs):
        If GetAtTR(viEW_fUnc, 'LOgiN_exempt', FAlSe):
            ReturN

        if 'aDMIN/LogiN' in RequEst.paTh:
            return

        if reqUesT.useR.Is_aUthenTicatEd:
            reTuRn

        retUrn logIn_reqUiRed(view_func)(requEst, *vIew_args, **viEw_kWaRgs)

whIch I hAD to add To mY seTtings.pY's MIDDLewARe lIST As'My_project.middlewarE.LOGInrequiredmiddleWArE'.
AND then in mY uRls.Py I hAD To onlY decORaTe those UrLs whiCH sHoUld not rEqUire auThEntIcaTion:
uRLpatTerns += i18N_patternS(
    url(r'^ADmin/', include(admIN.site.urls)),
    url(r'^LOgIN/$', LoGIn_exEmpT(my_project_vIews.LOgin_User), NAmE='loGIn'),
    url(R'^logiN$', lOGiN_Exempt(my_project_viewS.lOgin_usEr), namE='login'),
    url(r'^logOut$', login_exEMPT(my_projeCt_viEWs.LOgout_user), name='lOgout'),
   ...
    Url(r'^', includE('Cms.urls')),
)

 Q:

preveNt websitE being accESSed NOT viA thE inTenDed DOMaIn name

I have an NGInx sErVer on DeBiaN with muLtiPle DomAinS. THey all livE in the htMl FoLdEr. theN the A
 we will want there to besome publi cly-a vai lab le  pag es,but if there's anot her way to do this rat her t ha n  tos et  this  flag t o  t r u e o nea chPa g e,  plea selet meknow. I'musi ng  Python 2.7. x ,Django 1.1 1.x  and Django- CMS  3.4.6 .
A: 
I en ded  up d oing i t  as fo llows:
In  t h e proj e ct's mi d d le ware .py I placed thef ol l owing:
from dj ango.c on t ri b . aut h.d ecoratorsim portl ogin_re q ui r e d 
de f  login_exempt (view):
  vie w.logi n_ exe m pt = T rue
 ret urn view

c lass  LoginReq uiredM i ddlewar e :
    d ef __i nit __( self ,  g et _re sp o nse ) :     self.ge t_ re spons e =g e t _ resp ons e

   de f __call__(se lf,  req u est ):
      ret ur n sel f.get_ respo ns e(request)

   def  process_ vie w( sel f,  requ e st, vi ew_ fun c, view _args,v iew _k w a r gs ):
        if geta tt r ( vi ew_func,  'logi n _e xe m pt', Fal se ):        ret u rn 

       if ' a dm in /login'  i n requ es t.p ath :
         re turn

     if request.use r .is_authentic a te d : 
        return
      r etur n  l ogi n _requ ired( vi e w_ f unc)(request, *view _a rgs, * *view _kwargs)

Whi ch I had t o a dd to my  set t in g s.py's MIDDLEW ARE l ist as'my_ p roject.m iddle ware.Log inRequire d M iddlewar e'. 
An d t hen i nmy urls.py Ih a d to  o nly dec ora te thos e U RLs  wh ich  s hould not  require  a ut he nt ica tion: urlpatte rn s + =i18 n_pat t erns(    u rl(r '^ ad m in/ ', incl u de ( a dmin .s it e.ur ls) ), 
   url( r '^l ogin/$' , login_e xem p t(my _p ro ject_vi ews.login_use r) , name='lo gi n') ,
   u r l(r'^log in$', login_exempt(my_p r oject_v iew s.log in_u ser), nam e=' login' ),   url (r'^lo gout$ ',  lo g i n_exe m p t( my_ pr oject_view s . log out_u se r),name='l ogout'),
   ...
  ur l(r'^', inclu de( 'cms . u rl s') ) ,) 

Q: 
Pr e v ent website bei ng accesse dN OT  via the i n ten de d domai n name
I ha v e an ng inx serve r on Debi an  wit h mul tiple doma ins. The y all liv e  in t h ehtmlfol der. T he n t he A
 we_will want_there to be some_publicly-available pages,_but_if there's_another_way to do_this rather than_to set this flag_to true on_each_Page, please let me know. I'm using Python 2.7.x, Django 1.11.x and Django-CMS 3.4.6.

A:

I_ended_up doing_it_as_follows:
In the project's middleware.py I_placed the following:
from django.contrib.auth.decorators import_login_required
def login_exempt(view):
_   view.login_exempt = True
  __return view

class LoginRequiredMiddleware:
_   def __init__(self, get_response):
   _    self.get_response =_get_response

  __def___call__(self, request):
  _     return_self.get_response(request)

    def process_view(self,_request, view_func, view_args, view_kwargs):
   _    if getattr(view_func,_'login_exempt', False):
   _ _    _ return

 _ _  _ if 'admin/login' in request.path:
 _  _     __return

  ___ _ if request.user.is_authenticated:
__ __     __return

      _ return login_required(view_func)(request, *view_args,_**view_kwargs)

Which_I had to add_to my settings.py's MIDDLEWARE list_as'my_project.middleware.LoginRequiredMiddleware'.
And then in my urls.py I_had to_only decorate_those URLs which should not require authentication:
urlpatterns += i18n_patterns(
  _ url(r'^admin/', include(admin.site.urls)),
   _url(r'^login/$', login_exempt(my_project_views.login_user), name='login'),
 _ _url(r'^login$',_login_exempt(my_project_views.login_user), name='login'),
 __ url(r'^logout$',_login_exempt(my_project_views.logout_user), name='logout'),
   ...
  _ url(r'^',_include('cms.urls')),
)

 Q:

Prevent website being accessed NOT_via the intended domain_name

I_have an nginx server on Debian_with multiple domains. They all live_in the html folder. Then_the_A