Well, I'd certainly be glad to if it might help someone out.

I came up with two solutions, both of which work fairly well.

1. Custom urls and views
   
In my app, I added some urls to urls.py: 

from django.conf.urls import patterns, url

urlpatterns = patterns(
    'theme.views',
    url(r'^login/$', 'login'),
    url(r'^create_user/$', 'create_user'),
    url(r'^contact-us-form/$', 'contact_form'),
)


which point to views I created to handle each situation. Probably the best 
place to look for best practice on authenticated users, etc is the 
docs: https://docs.djangoproject.com/en/1.8/topics/auth/default/

It has some great sample views for common situations. I passed the 
username, password, email, etc through JavaScript as POST data. eg:

$(function() {
      $("#signupSubmit").click( function() {
        var $form = $( "#signup_form" ),
        user = $form.find( "input[id='signupName']" ).val(),
        email = $form.find( "input[id='signupEmail']" ).val(),
        url = "create_user/";

        // Send the data using post
        var posting = $.post( url, { userName: user, email: email  } );

          // Put the results in a div
        posting.done(function( data ) {
        $("#modal_msg").addClass(data['msg'][1]);
        $("#modal_msg").attr("style", "display: block");
        $("#modal_msg").empty().append( data['msg'][0] 
).slideDown().delay(3000).slideUp();
        //$("#signUpModal").delay(4000).modal('hide');
      });
   });
});


which can be accessed in the view through the POST dict, for example: 
`username = request.POST['userName']`. In this situation, I also passed a 
list which included some formatting information for the alert box, and a 
message.

Just don't forget to include the crsf token. Also, when logging a user in, 
or doing other authentication tasks, it makes the most sense to refresh the 
page, even if you're using js.

2. Page processors

In this situation, the views are basically identical, but no urls.py or 
view.py file is needed. Just create a `page_processors.py` file in your 
base app directory (with the views in it), and wrap the view with the 
decorator `@processor_for(PageForView)`. Here's some more info on page 
processors 
<http://mezzanine.jupo.org/docs/content-architecture.html#page-processors>

Cheers!

On Sunday, 16 August 2015 16:33:20 UTC-7, Stephen McDonald wrote:
>
> Oh, please post the solution! One of the big goals with the mailing 
> list is having searchable problems and solutions. You never know who 
> it might end up helping. 
>
> On 8/17/15, Avery Laird <[email protected] <javascript:>> wrote: 
> > I solved my own problem a couple days ago. I won't go through the 
> details 
> > here, but if someone else is having the same problem feel free to email 
> me! 
> > 
> > On Wednesday, 12 August 2015 17:44:48 UTC-7, Avery Laird wrote: 
> >> 
> >> Hello, 
> >> 
> >> I've been working on a project where the login form is on the front 
> page, 
> >> 
> >> `/`, not at `/accounts/login/`. At first, I thought an ajax post -- or 
> a 
> >> simple form post -- to that url would be the best approach, but once I 
> >> took 
> >> a look at the view I realized I wasn't sure where to start. It relies 
> on 
> >> the form at `mezzanine.accounts.forms`, and that form being in the 
> >> context. 
> >> It seemed that simply passing the form data via ajax may not be the 
> best 
> >> approach, so I considered some different approaches. I thought about an 
> >> inclusion tag, modified urls file, modified views file, and various 
> other 
> >> 
> >> -- increasingly sketchy -- methods. It was at that point I realized I 
> had 
> >> 
> >> no idea what the best practice for this situation would be. I thought I 
> >> might find a cleaner solution by asking around a bit. 
> >> 
> >> Any suggestions? 
> >> 
> >> Thanks for any insight! 
> >> 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Mezzanine Users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to [email protected] <javascript:>. 
> > For more options, visit https://groups.google.com/d/optout. 
> > 
>
>
> -- 
> Stephen McDonald 
> http://jupo.org 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to