gpranav88-zz / clothzy-MVP

Clothzy MVP
0 stars 0 forks source link

Problems integrating Django and AngularJS #18

Closed agamdua closed 10 years ago

agamdua commented 10 years ago

Here's the situation:

  1. Django code works (API clearly outputs data as a JSON, as required)
  2. AngularJS app works.

They don't work together.

The problem is not data receiving, have not reached there yet.

Django is not recognising the AngularJS routes / vice versa - there is a 404 or GET request for a wrong file, e.g., on localhost/product(s)/1 it shows 1.html as a 404.

I am absolutely sure that its a 'semi-colon' kind of error. Some basic thing missed out.

Another pair of eyes required, hence assigned to Pranav.

Pranav: There are two approaches which are quick & promising:

  1. This is the repo from the video : https://github.com/gkappel/demo-d201305
  2. You already know about this one (Mourafiq or whatever) : https://github.com/mouradmourafiq/django-angular-blog/tree/master/blog

Just please check the Django side, which one resembles our code closer, I'll remodel the Angular according to that.

Longer options:

  1. This is a very popular seed project for Django and Angular: https://github.com/zackargyle/angularjs-django-rest-framework-seed
  2. Restangular (this is best approach but will most probably fail the deadline - not more than Tuesday, but even Monday != 25th, so yeah).

Wild card: http://django-angular.readthedocs.org/en/latest/index.html Well maintained, but doesn't seem to use an API - no idea beyond that.

agamdua commented 10 years ago

@gpranav88 - branch is dj-ng.

I'm tired of configuration madness, written zero code today. 5 options in Issue, go with one and tell me which looks best.

Completely your call, please comment answer after reviewing and reassign to me. I'll modify AngularJS accordingly.

I'm off to rest. No, not REST. rest. bye. (yes, it gets frustrating, I hate broken things).

agamdua commented 10 years ago

Kartik's code written today can be pulled in later, more worried about having a homepage render at all at the moment.

hsinha commented 10 years ago

Django's built in templating engine has syntax which is similar to Angular. Both use {{}} for variables. This could be a source of the issues you're facing.

Use the %verbatim% tag in Django to prevent it from rendering the template server side .

Kartik's code written today can be pulled in later, more worried about having a homepage render at all at the moment.

— Reply to this email directly or view it on GitHubhttps://github.com/agamdua/clothzy/issues/18#issuecomment-33140740 .

agamdua commented 10 years ago

@hsinha - Na, I've taken care of that using an $interpolator: https://github.com/agamdua/clothzy/blob/dj-ng/clothzy/static/js/clothzy.js#L39

The routes aren't being recognised, I think its on the Angular connection side.

Somewhere I've read that $resource doesn't play well with Django-REST. Its counterintuitive, since the whole point of the $resource wrapper over $http is for RESTful interaction, so I've still kept that there.

Can't really evaluate that though until the 404 to the template/partial disappears and our site appears.

gpranav88-zz commented 10 years ago

we aren't using the django templates at all, so no chance of syntax collisions. I checked by disabling CORS, and other changes to clothzy.js, got a 404 error for home.html. Moved the home.html to static folder instead of templates, and it worked. Changed the route(added static in path) as: .when ('/',{ templateUrl:'static/home.html', controller:'homePageController' }) Guess you can't access django's template files from client. Now api requests may have a CORS issue, but from what i read, it shouldn't be a big issue.

agamdua commented 10 years ago

cors should be handled by the django-cors package. I think I forgot to add it to requirements, I'll just do that.

Also, collecting templates is a pain in the thing in Django, it'll work if we add it to templates dir.

You're right, at the moment we aren't using Django templates, since the templates extending etc is all commented out: https://github.com/agamdua/clothzy/blob/dj-ng/clothzy/static/home.html#L1

And $interpolation doesn't affect the Django code if we aren't using the templates, so can switch that out tomorrow.

I am absolutely sure that its a 'semi-colon' kind of error. Some basic thing missed out.

Always this. Always.

At peace now. See you guys after lunch, thanks @hsinha and @gpranav88!

For the record, this is what Pranav's commit just did: screen shot 2014-01-24 at 12 44 08 am

gpranav88-zz commented 10 years ago

fixed.

gpranav88-zz commented 10 years ago

fixed.